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.



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

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.



10
11
12
# File 'lib/mailhandler/receiving/notification/email.rb', line 10

def contacts
  @contacts
end

#current_stateObject (readonly)

Returns the value of attribute current_state.



16
17
18
# File 'lib/mailhandler/receiving/notification/email.rb', line 16

def current_state
  @current_state
end

#fromObject

Returns the value of attribute from.



10
11
12
# File 'lib/mailhandler/receiving/notification/email.rb', line 10

def from
  @from
end

#max_time_to_notifyObject

Returns the value of attribute max_time_to_notify.



10
11
12
# File 'lib/mailhandler/receiving/notification/email.rb', line 10

def max_time_to_notify
  @max_time_to_notify
end

#min_time_to_notifyObject

Returns the value of attribute min_time_to_notify.



10
11
12
# File 'lib/mailhandler/receiving/notification/email.rb', line 10

def min_time_to_notify
  @min_time_to_notify
end

#senderObject

Returns the value of attribute sender.



10
11
12
# File 'lib/mailhandler/receiving/notification/email.rb', line 10

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



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

def change_content_handler(content_handler)
  @content_handler = content_handler
end

#change_state(state) ⇒ Object



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

def change_state(state)
  @current_state = state
end

#notify(search) ⇒ Object



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

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



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

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