Class: Webspicy::Tester::Fakesmtp::Email

Inherits:
Object
  • Object
show all
Defined in:
lib/webspicy/tester/fakesmtp/email.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(data) ⇒ Email

Returns a new instance of Email.



6
7
8
# File 'lib/webspicy/tester/fakesmtp/email.rb', line 6

def initialize(data)
  @data = data
end

Instance Attribute Details

#dataObject (readonly)

Returns the value of attribute data.



9
10
11
# File 'lib/webspicy/tester/fakesmtp/email.rb', line 9

def data
  @data
end

Instance Method Details

#ccObject



23
24
25
26
# File 'lib/webspicy/tester/fakesmtp/email.rb', line 23

def cc
  @cc ||= data["cc"]["value"]
    .map{|h| h["address"] }
end

#fromObject



11
12
13
14
15
16
# File 'lib/webspicy/tester/fakesmtp/email.rb', line 11

def from
  @from ||= data["headerLines"]
    .select{|h| h["key"] == "from" }
    .map{|h| h["line"][/From:\s*(.*)$/, 1] }
    .first
end

#headersObject



41
42
43
44
45
46
47
# File 'lib/webspicy/tester/fakesmtp/email.rb', line 41

def headers
  @headers ||= data["headerLines"]
    .reduce(OpenStruct.new){|acc, h|
      acc[h["key"].downcase] = h["line"].split(': ')[1..].join(': ')
      acc
    }
end

#reply_toObject



28
29
30
31
32
# File 'lib/webspicy/tester/fakesmtp/email.rb', line 28

def reply_to
  @reply_to ||= data["headerLines"]
    .select{|h| h["key"] == "reply-to" }
    .map{|h| h["line"][/Reply-To:\s*(.*)$/, 1] }
end

#subjectObject



34
35
36
37
38
39
# File 'lib/webspicy/tester/fakesmtp/email.rb', line 34

def subject
  @subject ||= data["subject"] || data["headerLines"]
      .select{|h| h["key"] == "subject" }
      .map{|h| h["line"][/Subject:\s*(.*)$/, 1] }
      .first
end

#toObject



18
19
20
21
# File 'lib/webspicy/tester/fakesmtp/email.rb', line 18

def to
  @to ||= data["to"]["value"]
    .map{|h| h["address"] }
end