Class: Formatter::SupportEmails

Inherits:
Base
  • Object
show all
Defined in:
lib/bas/formatter/support_emails.rb

Overview

This class implements methods from the Formatter::Base module, tailored to format the Domain::Email structure for a dispatcher.

Constant Summary collapse

DEFAULT_TIME_ZONE =
"+00:00"

Instance Attribute Summary

Attributes inherited from Base

#template

Instance Method Summary collapse

Constructor Details

#initialize(config = {}) ⇒ SupportEmails

Initializes the formatter with essential configuration parameters.

timezone : expect an string with the time difference relative to the UTC. Example: “-05:00”



17
18
19
20
21
22
# File 'lib/bas/formatter/support_emails.rb', line 17

def initialize(config = {})
  super(config)

  @timezone = config[:timezone] || DEFAULT_TIME_ZONE
  @frecuency = config[:frecuency]
end

Instance Method Details

#format(support_emails_list) ⇒ Object

Implements the logic for building a formatted payload with the given template for support emails.


Params:

  • List<Domain::Email> support_emails_list: list of support emails.


raises Formatter::Exceptions::InvalidData when invalid data is provided.


returns String payload: formatted payload suitable for a Dispatcher.



36
37
38
39
40
41
42
43
44
# File 'lib/bas/formatter/support_emails.rb', line 36

def format(support_emails_list)
  raise Formatter::Exceptions::InvalidData unless support_emails_list.all? do |support_email|
    support_email.is_a?(Domain::Email)
  end

  process_emails(support_emails_list).reduce("") do |payload, support_email|
    payload + build_template(Domain::Email::ATTRIBUTES, support_email)
  end
end