Class: Webspicy::Tester::Fakesendgrid::Email

Inherits:
Object
  • Object
show all
Defined in:
lib/webspicy/tester/fakesendgrid/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/fakesendgrid/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/fakesendgrid/email.rb', line 9

def data
  @data
end

Instance Method Details

#bccObject



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

def bcc
  @bcc ||= data["personalizations"]
    .select{|h| h.key? "bcc" }
    .map{|(h)| h["bcc"] }
    .flatten
    .map{|(h)| h["email"] }
end

#ccObject



25
26
27
28
29
30
31
# File 'lib/webspicy/tester/fakesendgrid/email.rb', line 25

def cc
  @cc ||= data["personalizations"]
    .select{|h| h.key? "cc" }
    .map{|(h)| h["cc"] }
    .flatten
    .map{|(h)| h["email"] }
end

#fromObject



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

def from
  @from ||= data['from']['name'] ?
    "#{data['from']['name']} <#{data['from']['email']}>" :
    data['from']['email']
end

#headersObject



45
46
47
48
49
50
# File 'lib/webspicy/tester/fakesendgrid/email.rb', line 45

def headers
  @headers ||= data["headers"].reduce(OpenStruct.new){|acc, (key, value)|
    acc[key.downcase] = value
    acc
  }
end

#subjectObject



41
42
43
# File 'lib/webspicy/tester/fakesendgrid/email.rb', line 41

def subject
  @subject ||= data["subject"]
end

#toObject



17
18
19
20
21
22
23
# File 'lib/webspicy/tester/fakesendgrid/email.rb', line 17

def to
  @to ||= data["personalizations"]
    .select{|h| h.key? "to" }
    .map{|(h)| h["to"] }
    .flatten
    .map{|(h)| h["email"] }
end