Class: Funktional::Email
- Inherits:
-
Object
- Object
- Funktional::Email
- Defined in:
- lib/funktional/email.rb
Instance Attribute Summary collapse
-
#matches ⇒ Object
Returns the value of attribute matches.
-
#original ⇒ Object
Returns the value of attribute original.
Class Method Summary collapse
Instance Method Summary collapse
- #<=>(other) ⇒ Object
- #body ⇒ Object
- #calculate_matches ⇒ Object
- #check_containing ⇒ Object
- #check_from ⇒ Object
- #check_subject ⇒ Object
- #check_to ⇒ Object
- #from ⇒ Object
-
#initialize(email, expected) ⇒ Email
constructor
A new instance of Email.
- #subject ⇒ Object
- #to ⇒ Object
- #total_matches ⇒ Object
Constructor Details
#initialize(email, expected) ⇒ Email
Returns a new instance of Email.
12 13 14 15 16 |
# File 'lib/funktional/email.rb', line 12 def initialize(email, expected) @original = email @expected = expected calculate_matches end |
Instance Attribute Details
#matches ⇒ Object
Returns the value of attribute matches.
10 11 12 |
# File 'lib/funktional/email.rb', line 10 def matches @matches end |
#original ⇒ Object
Returns the value of attribute original.
9 10 11 |
# File 'lib/funktional/email.rb', line 9 def original @original end |
Class Method Details
.find_closest(emails, expected) ⇒ Object
4 5 6 7 |
# File 'lib/funktional/email.rb', line 4 def self.find_closest(emails, expected) emails = emails.map { |email| new(email, expected) } emails.sort.first end |
Instance Method Details
#<=>(other) ⇒ Object
23 24 25 |
# File 'lib/funktional/email.rb', line 23 def <=>(other) other.total_matches <=> total_matches end |
#body ⇒ Object
72 73 74 |
# File 'lib/funktional/email.rb', line 72 def body @original.body.raw_source end |
#calculate_matches ⇒ Object
18 19 20 21 |
# File 'lib/funktional/email.rb', line 18 def calculate_matches @matches = {} @expected.map { |expect| self.send "check_#{expect.first}" } end |
#check_containing ⇒ Object
49 50 51 52 53 54 55 56 57 58 |
# File 'lib/funktional/email.rb', line 49 def check_containing should_contain = @expected[:containing] should_contain = [should_contain] unless should_contain.is_a? Array matches = [] should_contain.each do |should_i| matches << should_i if body =~ /#{Regexp.escape(should_i)}/ end @matches[:containing] = matches if matches.any? end |
#check_from ⇒ Object
35 36 37 |
# File 'lib/funktional/email.rb', line 35 def check_from @matches[:from] = from if from.present? and (@expected[:from] == from) end |
#check_subject ⇒ Object
43 44 45 46 47 |
# File 'lib/funktional/email.rb', line 43 def check_subject if subject.present? and (@expected[:subject] == subject) @matches[:subject] = subject end end |
#check_to ⇒ Object
39 40 41 |
# File 'lib/funktional/email.rb', line 39 def check_to @matches[:to] = to if to.present? and (@expected[:to] == to) end |
#from ⇒ Object
60 61 62 |
# File 'lib/funktional/email.rb', line 60 def from @original.from[0] end |
#subject ⇒ Object
68 69 70 |
# File 'lib/funktional/email.rb', line 68 def subject @original.subject end |
#to ⇒ Object
64 65 66 |
# File 'lib/funktional/email.rb', line 64 def to @original.to[0] end |
#total_matches ⇒ Object
27 28 29 30 31 32 33 |
# File 'lib/funktional/email.rb', line 27 def total_matches if @matches.has_key? :containing @matches.size + (@matches[:containing].size - 1) else @matches.size end end |