Class: MailHandler::Receiving::Notification::Email

Inherits:
Object
  • Object
show all
Defined in:
lib/mailhandler/receiving/notification/email.rb

Overview

notification in form of sent email

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(sender, from, to, min_time_to_notify = 60) ⇒ Email

Returns a new instance of Email.



20
21
22
23
24
25
26
27
28
# File 'lib/mailhandler/receiving/notification/email.rb', line 20

def initialize(sender, from, to, min_time_to_notify = 60)
  @min_time_to_notify = min_time_to_notify

  @sender = sender
  @from = from
  @contacts = to
  init_state
  change_content_handler(EmailContent.new)
end

Instance Attribute Details

#contactsObject

Returns the value of attribute contacts.



12
13
14
# File 'lib/mailhandler/receiving/notification/email.rb', line 12

def contacts
  @contacts
end

#current_stateObject (readonly)

Returns the value of attribute current_state.



18
19
20
# File 'lib/mailhandler/receiving/notification/email.rb', line 18

def current_state
  @current_state
end

#fromObject

Returns the value of attribute from.



12
13
14
# File 'lib/mailhandler/receiving/notification/email.rb', line 12

def from
  @from
end

#max_time_to_notifyObject

Returns the value of attribute max_time_to_notify.



12
13
14
# File 'lib/mailhandler/receiving/notification/email.rb', line 12

def max_time_to_notify
  @max_time_to_notify
end

#min_time_to_notifyObject

Returns the value of attribute min_time_to_notify.



12
13
14
# File 'lib/mailhandler/receiving/notification/email.rb', line 12

def min_time_to_notify
  @min_time_to_notify
end

#senderObject

Returns the value of attribute sender.



12
13
14
# File 'lib/mailhandler/receiving/notification/email.rb', line 12

def sender
  @sender
end

Instance Method Details

#change_content_handler(content_handler) ⇒ Object

Allow users to specify their own content classes. Class must match by methods to the interface of MailHandler::Receiving::Notification::EmailContent



48
49
50
# File 'lib/mailhandler/receiving/notification/email.rb', line 48

def change_content_handler(content_handler)
  @content_handler = content_handler
end

#change_state(state) ⇒ Object



36
37
38
# File 'lib/mailhandler/receiving/notification/email.rb', line 36

def change_state(state)
  @current_state = state
end

#notify(search) ⇒ Object



30
31
32
33
34
# File 'lib/mailhandler/receiving/notification/email.rb', line 30

def notify(search)
  @max_time_to_notify = search.max_duration
  init_state if Time.now - search.started_at < min_time_to_notify
  @current_state.notify(search)
end

#send_email(type, search) ⇒ Object



40
41
42
43
44
# File 'lib/mailhandler/receiving/notification/email.rb', line 40

def send_email(type, search)
  verify_email_type(type)
  content = @content_handler.retrieve(type, search.options, Time.now - search.started_at, from, contacts)
  sender.send_email content
end