@@ -108,11 +108,15 @@ class IMAP
108
108
# When a set includes <tt>*</tt>, some methods may have surprising behavior.
109
109
#
110
110
# For example, #complement treats <tt>*</tt> as its own number. This way,
111
- # the #intersection of a set and its #complement will always be empty.
112
- # This is not how an \IMAP server interprets the set: it will convert
113
- # <tt>*</tt> to either the number of messages in the mailbox or +UIDNEXT+,
114
- # as appropriate. And there _will_ be overlap between a set and its
115
- # complement after #limit is applied to each:
111
+ # the #intersection of a set and its #complement will always be empty. And
112
+ # <tt>*</tt> is sorted as greater than any other number in the set. This is
113
+ # not how an \IMAP server interprets the set: it will convert <tt>*</tt> to
114
+ # the number of messages in the mailbox, the +UID+ of the last message in
115
+ # the mailbox, or +UIDNEXT+, as appropriate. Several methods have an
116
+ # argument for how <tt>*</tt> should be interpreted.
117
+ #
118
+ # But, for example, this means that there may be overlap between a set and
119
+ # its complement after #limit is applied to each:
116
120
#
117
121
# ~Net::IMAP::SequenceSet["*"] == Net::IMAP::SequenceSet[1..(2**32-1)]
118
122
# ~Net::IMAP::SequenceSet[1..5] == Net::IMAP::SequenceSet["6:*"]
@@ -179,9 +183,9 @@ class IMAP
179
183
# - #include_star?: Returns whether the set contains <tt>*</tt>.
180
184
#
181
185
# <i>Minimum and maximum value elements:</i>
182
- # - #min: Returns one or more minimum numbers in the set.
183
- # - #max: Returns one or more maximum numbers in the set.
184
- # - #minmax: Returns the minimum and maximum numbers in the set.
186
+ # - #min: Returns one or more of the lowest numbers in the set.
187
+ # - #max: Returns one or more of the highest numbers in the set.
188
+ # - #minmax: Returns the lowest and highest numbers in the set.
185
189
#
186
190
# <i>Accessing value by offset in sorted set:</i>
187
191
# - #[] (aliased as #slice): Returns the number or consecutive subset at a
@@ -643,7 +647,14 @@ def full?; @tuples == [[1, STAR_INT]] end
643
647
# Net::IMAP::SequenceSet["1:5"] | 2 | [4..6, 99]
644
648
# #=> Net::IMAP::SequenceSet["1:6,99"]
645
649
#
646
- # Related: #add, #merge
650
+ # Related: #add, #merge, #&, #-, #^, #~
651
+ #
652
+ # ==== Set identities
653
+ #
654
+ # <tt>lhs | rhs</tt> is equivalent to:
655
+ # * <tt>rhs | lhs</tt> (commutative)
656
+ # * <tt>~(~lhs & ~rhs)</tt> (De Morgan's Law)
657
+ # * <tt>(lhs & rhs) ^ (lhs ^ rhs)</tt>
647
658
def |( other ) remain_frozen dup . merge other end
648
659
alias :+ :|
649
660
alias union :|
@@ -662,7 +673,17 @@ def |(other) remain_frozen dup.merge other end
662
673
# Net::IMAP::SequenceSet[1..5] - 2 - 4 - 6
663
674
# #=> Net::IMAP::SequenceSet["1,3,5"]
664
675
#
665
- # Related: #subtract
676
+ # Related: #subtract, #|, #&, #^, #~
677
+ #
678
+ # ==== Set identities
679
+ #
680
+ # <tt>lhs - rhs</tt> is equivalent to:
681
+ # * <tt>~r - ~l</tt>
682
+ # * <tt>lhs & ~rhs</tt>
683
+ # * <tt>~(~lhs | rhs)</tt>
684
+ # * <tt>lhs & (lhs ^ rhs)</tt>
685
+ # * <tt>lhs ^ (lhs & rhs)</tt>
686
+ # * <tt>rhs ^ (lhs | rhs)</tt>
666
687
def -( other ) remain_frozen dup . subtract other end
667
688
alias difference :-
668
689
@@ -680,7 +701,17 @@ def -(other) remain_frozen dup.subtract other end
680
701
# Net::IMAP::SequenceSet[1..5] & [2, 4, 6]
681
702
# #=> Net::IMAP::SequenceSet["2,4"]
682
703
#
683
- # <tt>(seqset & other)</tt> is equivalent to <tt>(seqset - ~other)</tt>.
704
+ # Related: #intersect?, #|, #-, #^, #~
705
+ #
706
+ # ==== Set identities
707
+ #
708
+ # <tt>lhs & rhs</tt> is equivalent to:
709
+ # * <tt>rhs & lhs</tt> (commutative)
710
+ # * <tt>~(~lhs | ~rhs)</tt> (De Morgan's Law)
711
+ # * <tt>lhs - ~rhs</tt>
712
+ # * <tt>lhs - (lhs - rhs)</tt>
713
+ # * <tt>lhs - (lhs ^ rhs)</tt>
714
+ # * <tt>lhs ^ (lhs - rhs)</tt>
684
715
def &( other )
685
716
remain_frozen dup . subtract SequenceSet . new ( other ) . complement!
686
717
end
@@ -700,8 +731,16 @@ def &(other)
700
731
# Net::IMAP::SequenceSet[1..5] ^ [2, 4, 6]
701
732
# #=> Net::IMAP::SequenceSet["1,3,5:6"]
702
733
#
703
- # <tt>(seqset ^ other)</tt> is equivalent to <tt>((seqset | other) -
704
- # (seqset & other))</tt>.
734
+ # Related: #|, #&, #-, #~
735
+ #
736
+ # ==== Set identities
737
+ #
738
+ # <tt>lhs ^ rhs</tt> is equivalent to:
739
+ # * <tt>rhs ^ lhs</tt> (commutative)
740
+ # * <tt>~lhs ^ ~rhs</tt>
741
+ # * <tt>(lhs | rhs) - (lhs & rhs)</tt>
742
+ # * <tt>(lhs - rhs) | (rhs - lhs)</tt>
743
+ # * <tt>(lhs ^ other) ^ (other ^ rhs)</tt>
705
744
def ^( other ) remain_frozen ( dup | other ) . subtract ( self & other ) end
706
745
alias xor :^
707
746
@@ -719,7 +758,12 @@ def ^(other) remain_frozen (dup | other).subtract(self & other) end
719
758
# ~Net::IMAP::SequenceSet["6:99,223:*"]
720
759
# #=> Net::IMAP::SequenceSet["1:5,100:222"]
721
760
#
722
- # Related: #complement!
761
+ # Related: #complement!, #|, #&, #-, #^
762
+ #
763
+ # ==== Set identities
764
+ #
765
+ # <tt>~set</tt> is equivalent to:
766
+ # * <tt>full - set</tt>, where "full" is Net::IMAP::SequenceSet.full
723
767
def ~; remain_frozen dup . complement! end
724
768
alias complement :~
725
769
@@ -731,7 +775,10 @@ def ~; remain_frozen dup.complement! end
731
775
#
732
776
# #string will be regenerated. Use #merge to add many elements at once.
733
777
#
734
- # Related: #add?, #merge, #union
778
+ # Use #append to append new elements to #string. See
779
+ # Net::IMAP@Ordered+and+Normalized+Sets.
780
+ #
781
+ # Related: #add?, #merge, #union, #append
735
782
def add ( element )
736
783
tuple_add input_to_tuple element
737
784
normalize!
@@ -742,6 +789,10 @@ def add(element)
742
789
#
743
790
# Unlike #add, #merge, or #union, the new value is appended to #string.
744
791
# This may result in a #string which has duplicates or is out-of-order.
792
+ #
793
+ # See Net::IMAP@Ordered+and+Normalized+Sets.
794
+ #
795
+ # Related: #add, #merge, #union
745
796
def append ( entry )
746
797
modifying!
747
798
tuple = input_to_tuple entry
@@ -890,21 +941,21 @@ def subtract(*sets)
890
941
# This is useful when the given order is significant, for example in a
891
942
# ESEARCH response to IMAP#sort.
892
943
#
944
+ # See Net::IMAP@Ordered+and+Normalized+Sets.
945
+ #
893
946
# Related: #each_entry, #elements
894
947
def entries ; each_entry . to_a end
895
948
896
949
# Returns an array of ranges and integers and <tt>:*</tt>.
897
950
#
898
951
# The returned elements are sorted and coalesced, even when the input
899
- # #string is not. <tt>*</tt> will sort last. See #normalize.
952
+ # #string is not. <tt>*</tt> will sort last. See #normalize,
953
+ # Net::IMAP@Ordered+and+Normalized+Sets.
900
954
#
901
955
# By itself, <tt>*</tt> translates to <tt>:*</tt>. A range containing
902
956
# <tt>*</tt> translates to an endless range. Use #limit to translate both
903
957
# cases to a maximum value.
904
958
#
905
- # The returned elements will be sorted and coalesced, even when the input
906
- # #string is not. <tt>*</tt> will sort last. See #normalize.
907
- #
908
959
# Net::IMAP::SequenceSet["2,5:9,6,*,12:11"].elements
909
960
# #=> [2, 5..9, 11..12, :*]
910
961
#
@@ -915,15 +966,13 @@ def elements; each_element.to_a end
915
966
# Returns an array of ranges
916
967
#
917
968
# The returned elements are sorted and coalesced, even when the input
918
- # #string is not. <tt>*</tt> will sort last. See #normalize.
969
+ # #string is not. <tt>*</tt> will sort last. See #normalize,
970
+ # Net::IMAP@Ordered+and+Normalized+Sets.
919
971
#
920
972
# <tt>*</tt> translates to an endless range. By itself, <tt>*</tt>
921
973
# translates to <tt>:*..</tt>. Use #limit to set <tt>*</tt> to a maximum
922
974
# value.
923
975
#
924
- # The returned ranges will be sorted and coalesced, even when the input
925
- # #string is not. <tt>*</tt> will sort last. See #normalize.
926
- #
927
976
# Net::IMAP::SequenceSet["2,5:9,6,*,12:11"].ranges
928
977
# #=> [2..2, 5..9, 11..12, :*..]
929
978
# Net::IMAP::SequenceSet["123,999:*,456:789"].ranges
@@ -935,7 +984,7 @@ def ranges; each_range.to_a end
935
984
# Returns a sorted array of all of the number values in the sequence set.
936
985
#
937
986
# The returned numbers are sorted and de-duplicated, even when the input
938
- # #string is not. See #normalize.
987
+ # #string is not. See #normalize, Net::IMAP@Ordered+and+Normalized+Sets .
939
988
#
940
989
# Net::IMAP::SequenceSet["2,5:9,6,12:11"].numbers
941
990
# #=> [2, 5, 6, 7, 8, 9, 11, 12]
@@ -967,6 +1016,8 @@ def numbers; each_number.to_a end
967
1016
# no sorting, deduplication, or coalescing. When #string is in its
968
1017
# normalized form, this will yield the same values as #each_element.
969
1018
#
1019
+ # See Net::IMAP@Ordered+and+Normalized+Sets.
1020
+ #
970
1021
# Related: #entries, #each_element
971
1022
def each_entry ( &block ) # :yields: integer or range or :*
972
1023
return to_enum ( __method__ ) unless block_given?
@@ -977,7 +1028,7 @@ def each_entry(&block) # :yields: integer or range or :*
977
1028
# and returns self. Returns an enumerator when called without a block.
978
1029
#
979
1030
# The returned numbers are sorted and de-duplicated, even when the input
980
- # #string is not. See #normalize.
1031
+ # #string is not. See #normalize, Net::IMAP@Ordered+and+Normalized+Sets .
981
1032
#
982
1033
# Related: #elements, #each_entry
983
1034
def each_element # :yields: integer or range or :*
@@ -1400,6 +1451,7 @@ def complement!
1400
1451
#
1401
1452
# The returned set's #string is sorted and deduplicated. Adjacent or
1402
1453
# overlapping elements will be merged into a single larger range.
1454
+ # See Net::IMAP@Ordered+and+Normalized+Sets.
1403
1455
#
1404
1456
# Net::IMAP::SequenceSet["1:5,3:7,10:9,10:11"].normalize
1405
1457
# #=> Net::IMAP::SequenceSet["1:7,9:11"]
@@ -1412,7 +1464,7 @@ def normalize
1412
1464
end
1413
1465
1414
1466
# Resets #string to be sorted, deduplicated, and coalesced. Returns
1415
- # +self+.
1467
+ # +self+. See Net::IMAP@Ordered+and+Normalized+Sets.
1416
1468
#
1417
1469
# Related: #normalize, #normalized_string
1418
1470
def normalize!
@@ -1422,11 +1474,13 @@ def normalize!
1422
1474
1423
1475
# Returns a normalized +sequence-set+ string representation, sorted
1424
1476
# and deduplicated. Adjacent or overlapping elements will be merged into
1425
- # a single larger range. Returns +nil+ when the set is empty .
1477
+ # a single larger range. See Net::IMAP@Ordered+and+Normalized+Sets .
1426
1478
#
1427
1479
# Net::IMAP::SequenceSet["1:5,3:7,10:9,10:11"].normalized_string
1428
1480
# #=> "1:7,9:11"
1429
1481
#
1482
+ # Returns +nil+ when the set is empty.
1483
+ #
1430
1484
# Related: #normalize!, #normalize
1431
1485
def normalized_string
1432
1486
@tuples . empty? ? nil : -@tuples . map { tuple_to_str _1 } . join ( "," )
0 commit comments