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

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

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
29
30
# 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
  set_content_handler(EmailContent.new)

end

Instance Attribute Details

#contactsObject (readonly)

Returns the value of attribute contacts.



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

def contacts
  @contacts
end

#current_stateObject (readonly)

Returns the value of attribute current_state.



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

def current_state
  @current_state
end

#fromObject (readonly)

Returns the value of attribute from.



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

def from
  @from
end

#max_time_to_notifyObject (readonly)

Returns the value of attribute max_time_to_notify.



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

def max_time_to_notify
  @max_time_to_notify
end

#min_time_to_notifyObject (readonly)

Returns the value of attribute min_time_to_notify.



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

def min_time_to_notify
  @min_time_to_notify
end

#senderObject (readonly)

Returns the value of attribute sender.



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

def sender
  @sender
end

Instance Method Details

#notify(search) ⇒ Object



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

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



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

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

#set_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



56
57
58
# File 'lib/mailhandler/receiving/notification/email.rb', line 56

def set_content_handler(content_handler)
  @content_handler = content_handler
end

#set_state(state) ⇒ Object



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

def set_state(state)

  @current_state = state

end