Class: Mailscope::Mailbox
- Inherits:
-
Struct
- Object
- Struct
- Mailscope::Mailbox
- Defined in:
- lib/mailscope/mailbox.rb
Overview
A recipient address, with the messages that landed in it. This is what the
left rail lists: one entry per "caixa de e-mail".
rubocop:disable Lint/StructNewOverride -- count reads better than any
alternative here, and this struct is never used as an enumerable.
Instance Attribute Summary collapse
-
#address ⇒ Object
Returns the value of attribute address.
-
#count ⇒ Object
Returns the value of attribute count.
-
#latest_at ⇒ Object
Returns the value of attribute latest_at.
-
#name ⇒ Object
Returns the value of attribute name.
Class Method Summary collapse
Instance Method Summary collapse
-
#hue ⇒ Object
Stable colour per mailbox, so the same address always looks the same.
- #initials ⇒ Object
- #label ⇒ Object
- #to_h ⇒ Object
Instance Attribute Details
#address ⇒ Object
Returns the value of attribute address
8 9 10 |
# File 'lib/mailscope/mailbox.rb', line 8 def address @address end |
#count ⇒ Object
Returns the value of attribute count
8 9 10 |
# File 'lib/mailscope/mailbox.rb', line 8 def count @count end |
#latest_at ⇒ Object
Returns the value of attribute latest_at
8 9 10 |
# File 'lib/mailscope/mailbox.rb', line 8 def latest_at @latest_at end |
#name ⇒ Object
Returns the value of attribute name
8 9 10 |
# File 'lib/mailscope/mailbox.rb', line 8 def name @name end |
Class Method Details
.absorb(buckets, addr, message) ⇒ Object
28 29 30 31 32 33 34 35 36 |
# File 'lib/mailscope/mailbox.rb', line 28 def self.absorb(buckets, addr, ) key = addr.address.to_s.downcase return if key.empty? box = buckets[key] ||= new(address: key, name: addr.name, count: 0, latest_at: nil) box.name ||= addr.name box.count += 1 box.latest_at = .sent_at if box.latest_at.nil? || .sent_at > box.latest_at end |
.index(messages) ⇒ Object
22 23 24 25 26 |
# File 'lib/mailscope/mailbox.rb', line 22 def self.index() buckets = {} .each { || .recipients.each { |addr| absorb(buckets, addr, ) } } buckets.values.sort_by { |box| [-box.latest_at.to_i, box.address] } end |
Instance Method Details
#hue ⇒ Object
Stable colour per mailbox, so the same address always looks the same.
18 |
# File 'lib/mailscope/mailbox.rb', line 18 def hue = address.to_s.each_byte.sum % 360 |
#initials ⇒ Object
11 12 13 14 15 |
# File 'lib/mailscope/mailbox.rb', line 11 def initials source = label.to_s letters = source.scan(/[[:alnum:]]+/).first(2).map { |w| w[0] }.join (letters.empty? ? source[0, 2] : letters).to_s.upcase end |
#label ⇒ Object
9 |
# File 'lib/mailscope/mailbox.rb', line 9 def label = name.to_s.empty? ? address : name |
#to_h ⇒ Object
20 |
# File 'lib/mailscope/mailbox.rb', line 20 def to_h = { address:, name:, count:, latest_at: latest_at&.iso8601 } |