Skip to content

Commit 5a0e5cb

Browse files
committed
✨ Add SequenceSet#deconstruct
Returns an array with `#normalized_string` when the sequence set is valid and an empty array otherwise.
1 parent 43e6a66 commit 5a0e5cb

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

lib/net/imap/sequence_set.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -384,6 +384,10 @@ def valid_string
384384
# Related: #valid_string, #normalized_string, #to_s
385385
def string; @string ||= normalized_string if valid? end
386386

387+
# Returns an array with #normalized_string when valid and an empty array
388+
# otherwise.
389+
def deconstruct; valid? ? [normalized_string] : [] end
390+
387391
# Assigns a new string to #string and resets #elements to match. It
388392
# cannot be set to an empty string—assign +nil+ or use #clear instead.
389393
# The string is validated but not normalized.

test/net/imap/test_sequence_set.rb

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -779,6 +779,18 @@ def test_inspect((expected, input, freeze))
779779
assert_equal str, set.string
780780
end
781781

782+
test "#deconstruct" do |data|
783+
set = SequenceSet.new(data[:input])
784+
str = data[:normalize]
785+
if str
786+
assert_equal [str], set.deconstruct
787+
set => SequenceSet[str]
788+
else
789+
assert_equal [], set.deconstruct
790+
set => SequenceSet[]
791+
end
792+
end
793+
782794
test "#normalized_string" do |data|
783795
set = SequenceSet.new(data[:input])
784796
assert_equal data[:normalize], set.normalized_string

0 commit comments

Comments
 (0)