Class: Protege::Gateway::Mail::References
- Inherits:
-
Object
- Object
- Protege::Gateway::Mail::References
- Includes:
- Enumerable
- Defined in:
- lib/protege/gateway/mail/references.rb
Overview
Value object representing an ordered chain of Message-IDs from the
References and In-Reply-To headers of an email thread.
Instances are frozen and Enumerable. Construct via .parse; build
reply chains with #with_parent_appended rather than mutating.
Class Method Summary collapse
-
.parse(items) ⇒ References
Parse a list of raw header values into a
Referenceschain.
Instance Method Summary collapse
-
#==(other) ⇒ Boolean
(also: #eql?)
Compare by element-wise value equality.
-
#each {|message_id| ... } ⇒ Enumerator, References
Yield each
MessageIdin order. -
#empty? ⇒ Boolean
Report whether the chain has no entries.
-
#first ⇒ MessageId?
Return the first
MessageIdin the chain. -
#hash ⇒ Integer
Hash by the underlying array contents.
-
#initialize(message_ids) ⇒ References
constructor
Wrap a pre-parsed array of +MessageId+s and freeze.
-
#size ⇒ Integer
Return the number of entries.
-
#to_a ⇒ Array<MessageId>
Return the underlying entries as a frozen array.
-
#with_parent_appended(parent) ⇒ References
Return a new
Referenceswithparentappended (immutable update).
Constructor Details
#initialize(message_ids) ⇒ References
Wrap a pre-parsed array of +MessageId+s and freeze. Prefer .parse.
38 39 40 41 |
# File 'lib/protege/gateway/mail/references.rb', line 38 def initialize() @items = .dup.freeze freeze end |
Class Method Details
.parse(items) ⇒ References
Parse a list of raw header values into a References chain.
nil entries and blank/whitespace-only strings are dropped; surviving entries are
normalized via MessageId.parse. Duplicates are preserved.
22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/protege/gateway/mail/references.rb', line 22 def parse(items) parsed = items.filter_map do |item| next if item.nil? stripped = item.to_s.strip next if stripped.empty? MessageId.parse(stripped) end new(parsed) end |
Instance Method Details
#==(other) ⇒ Boolean Also known as: eql?
Compare by element-wise value equality.
93 94 95 |
# File 'lib/protege/gateway/mail/references.rb', line 93 def ==(other) other.is_a?(References) && other.to_a == @items end |
#each {|message_id| ... } ⇒ Enumerator, References
Yield each MessageId in order.
48 49 50 |
# File 'lib/protege/gateway/mail/references.rb', line 48 def each(&) @items.each(&) end |
#empty? ⇒ Boolean
Report whether the chain has no entries.
62 63 64 |
# File 'lib/protege/gateway/mail/references.rb', line 62 def empty? @items.empty? end |
#first ⇒ MessageId?
Return the first MessageId in the chain.
55 56 57 |
# File 'lib/protege/gateway/mail/references.rb', line 55 def first @items.first end |
#hash ⇒ Integer
Hash by the underlying array contents.
101 102 103 |
# File 'lib/protege/gateway/mail/references.rb', line 101 def hash @items.hash end |
#size ⇒ Integer
Return the number of entries.
69 70 71 |
# File 'lib/protege/gateway/mail/references.rb', line 69 def size @items.size end |
#to_a ⇒ Array<MessageId>
Return the underlying entries as a frozen array.
76 77 78 |
# File 'lib/protege/gateway/mail/references.rb', line 76 def to_a @items end |
#with_parent_appended(parent) ⇒ References
Return a new References with parent appended (immutable update).
84 85 86 87 |
# File 'lib/protege/gateway/mail/references.rb', line 84 def with_parent_appended(parent) = parent.is_a?(MessageId) ? parent : MessageId.parse(parent) self.class.new(@items + []) end |