summaryrefslogtreecommitdiff
path: root/fake-service/lib/smail/contact.rb
blob: a07f0f840eb0ed9d85255b125bb81436a0af6518 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26

module Smail
  class Contact < Struct.new(:ident, :name, :addresses, :mails_received, :mails_sent, :last_received, :last_sent, :prev, :next)
    include Comparable

    def to_json(*args)
      {
        ident: self.ident,
        name: self.name,
        addresses: Array(self.addresses),
        mails_received: self.mails_received || 0,
        mails_sent: self.mails_sent || 0,
        last_received: self.last_received,
        last_sent: self.last_sent
      }.to_json(*args)
    end

    def comparison_value
      [(self.mails_received || 0) + (self.mails_sent || 0) * 0.8, self.last_received, self.last_sent]
    end

    def <=>(other)
      other.comparison_value <=> self.comparison_value
    end
  end
end