Class: MailHandler::Receiving::Notification::Email
- Inherits:
-
Object
- Object
- MailHandler::Receiving::Notification::Email
- Defined in:
- lib/mailhandler/receiving/notification/email.rb
Instance Attribute Summary collapse
-
#contacts ⇒ Object
readonly
Returns the value of attribute contacts.
-
#current_state ⇒ Object
readonly
Returns the value of attribute current_state.
-
#from ⇒ Object
readonly
Returns the value of attribute from.
-
#max_time_to_notify ⇒ Object
readonly
Returns the value of attribute max_time_to_notify.
-
#min_time_to_notify ⇒ Object
readonly
Returns the value of attribute min_time_to_notify.
-
#sender ⇒ Object
readonly
Returns the value of attribute sender.
Instance Method Summary collapse
-
#initialize(sender, from, to, min_time_to_notify = 60) ⇒ Email
constructor
A new instance of Email.
- #notify(search) ⇒ Object
- #send_email(type, search) ⇒ Object
-
#set_content_handler(content_handler) ⇒ Object
Allow users to specify their own content classes.
- #set_state(state) ⇒ Object
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
#contacts ⇒ Object (readonly)
Returns the value of attribute contacts.
13 14 15 |
# File 'lib/mailhandler/receiving/notification/email.rb', line 13 def contacts @contacts end |
#current_state ⇒ Object (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 |
#from ⇒ Object (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_notify ⇒ Object (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_notify ⇒ Object (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 |
#sender ⇒ Object (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., 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 |