Class: Net::IMAP::SearchResult
Relationships & Source Files | |
Super Chains via Extension / Inclusion / Inheritance | |
Class Chain:
self,
Array
|
|
Instance Chain:
self,
Array
|
|
Inherits: |
Array
|
Defined in: | lib/net/imap/search_result.rb |
Overview
An array of sequence numbers returned by #search, or unique identifiers returned by #uid_search.
For backward compatibility, SearchResult
inherits from Array.
Class Method Summary
-
.[](*seq_nums, modseq: nil)
Returns a
SearchResult
populated with the givenseq_nums
. -
.new(seq_nums, modseq: nil) ⇒ SearchResult
constructor
Returns a
SearchResult
populated with the givenseq_nums
.
Instance Attribute Summary
-
#modseq
readonly
A modification sequence number, as described by the
CONDSTORE
extension in [RFC7162 §3.1.6].
Instance Method Summary
-
#==(other)
Returns whether
other
is aSearchResult
with the same values and the same #modseq. -
#eql?(other) ⇒ Boolean
Hash equality.
-
#hash
Hash equality.
-
#inspect
Returns a string that represents the
SearchResult
. - #pretty_print(pp)
-
#to_s(type = "SEARCH")
Returns a string that follows the formal IMAP syntax.
-
#to_sequence_set
Converts the
SearchResult
into aSequenceSet
.
Constructor Details
.new(seq_nums, modseq: nil) ⇒ SearchResult
# File 'lib/net/imap/search_result.rb', line 29
def initialize(seq_nums, modseq: nil) super(seq_nums.to_ary.map { Integer _1 }) @modseq = Integer modseq if modseq end
Class Method Details
.[](*seq_nums, modseq: nil)
Instance Attribute Details
#modseq (readonly)
A modification sequence number, as described by the CONDSTORE
extension in [RFC7162 §3.1.6].
# File 'lib/net/imap/search_result.rb', line 23
attr_reader :modseq
Instance Method Details
#==(other)
Returns whether other
is a SearchResult
with the same values and the same #modseq. The order of numbers is irrelevant.
Net::IMAP::SearchResult[123, 456, modseq: 789] ==
Net::IMAP::SearchResult[123, 456, modseq: 789]
# => true
Net::IMAP::SearchResult[123, 456, modseq: 789] ==
Net::IMAP::SearchResult[456, 123, modseq: 789]
# => true
Net::IMAP::SearchResult[123, 456, modseq: 789] ==
Net::IMAP::SearchResult[987, 654, modseq: 789]
# => false
Net::IMAP::SearchResult[123, 456, modseq: 789] ==
Net::IMAP::SearchResult[1, 2, 3, modseq: 9999]
# => false
SearchResult
can be compared directly with Array, if #modseq is nil and the array is sorted.
Net::IMAP::SearchResult[9, 8, 6, 4, 1] == [1, 4, 6, 8, 9] # => true
Net::IMAP::SearchResult[3, 5, 7, modseq: 99] == [3, 5, 7] # => false
Note that Array#==
does require matching order and ignores #modseq.
[9, 8, 6, 4, 1] == Net::IMAP::SearchResult[1, 4, 6, 8, 9] # => false
[3, 5, 7] == Net::IMAP::SearchResult[3, 5, 7, modseq: 99] # => true
#eql?(other) ⇒ Boolean
Hash equality. Unlike #==, order will be taken into account.
#hash
Hash equality. Unlike #==, order will be taken into account.
#inspect
#pretty_print(pp)
[ GitHub ]# File 'lib/net/imap/search_result.rb', line 123
def pretty_print(pp) return super if modseq.nil? pp.text self.class.name + "[" pp.group_sub do pp.nest(2) do pp.breakable "" each do |num| pp.pp num pp.text "," pp.fill_breakable end pp.breakable "" pp.text "modseq: " pp.pp modseq end pp.breakable "" pp.text "]" end end
#to_s(type = "SEARCH")
Returns a string that follows the formal IMAP syntax.
data = Net::IMAP::SearchResult[2, 8, 32, 128, 256, 512]
data.to_s # => "* SEARCH 2 8 32 128 256 512"
data.to_s("SEARCH") # => "* SEARCH 2 8 32 128 256 512"
data.to_s("SORT") # => "* SORT 2 8 32 128 256 512"
data.to_s(nil) # => "2 8 32 128 256 512"
data = Net::IMAP::SearchResult[1, 3, 16, 1024, modseq: 2048].to_s
data.to_s # => "* SEARCH 1 3 16 1024 (MODSEQ 2048)"
data.to_s("SORT") # => "* SORT 1 3 16 1024 (MODSEQ 2048)"
data.to_s # => "1 3 16 1024 (MODSEQ 2048)"
#to_sequence_set
Converts the SearchResult
into a SequenceSet
.
Net::IMAP::SearchResult[9, 1, 2, 4, 10, 12, 3, modseq: 123_456]
.to_sequence_set
# => Net::IMAP::SequenceSet["1:4,9:10,12"]
# File 'lib/net/imap/search_result.rb', line 121
def to_sequence_set; SequenceSet[*self] end