Class: Rad::Letter

Inherits:
Object show all
Defined in:
lib/rad/mail/letter.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(properties) ⇒ Letter

Returns a new instance of Letter.



7
8
9
10
11
# File 'lib/rad/mail/letter.rb', line 7

def initialize properties
  properties.each do |k, v|
    send "#{k}=", v
  end
end

Instance Attribute Details

#bodyObject

Returns the value of attribute body.



5
6
7
# File 'lib/rad/mail/letter.rb', line 5

def body
  @body
end

#fromObject

Returns the value of attribute from.



5
6
7
# File 'lib/rad/mail/letter.rb', line 5

def from
  @from
end

#subjectObject

Returns the value of attribute subject.



5
6
7
# File 'lib/rad/mail/letter.rb', line 5

def subject
  @subject
end

#toObject

Returns the value of attribute to.



5
6
7
# File 'lib/rad/mail/letter.rb', line 5

def to
  @to
end

Instance Method Details

#deliverObject



20
21
22
23
# File 'lib/rad/mail/letter.rb', line 20

def deliver
  validate!
  mailer.deliver self
end

#to_hashObject Also known as: to_h



25
26
27
# File 'lib/rad/mail/letter.rb', line 25

def to_hash
  {from: from, to: to, subject: subject, body: body}
end

#validate!Object



13
14
15
16
17
18
# File 'lib/rad/mail/letter.rb', line 13

def validate!
  from || raise("letter :from not specified!")
  to || raise("letter :to not specified!")
  subject || raise("letter :subject not specified!")
  body || raise("letter :body not specified!") 
end