Class: Formatter::Pto

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

Overview

This class implements methods from the Formatter::Base module, tailored to format the Domain::Pto 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 = {}) ⇒ Pto

Initializes the Slack formatter with essential configuration parameters.

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



19
20
21
22
23
# File 'lib/bas/formatter/pto.rb', line 19

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

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

Instance Method Details

#format(ptos_list) ⇒ Object

Implements the logic for building a formatted payload with the given template for PTO’s.


Params:

  • List<Domain::Pto> pto_list: List of mapped PTO’s.


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


returns String payload, formatted payload suitable for a Dispatcher.



38
39
40
41
42
43
44
45
# File 'lib/bas/formatter/pto.rb', line 38

def format(ptos_list)
  raise Formatter::Exceptions::InvalidData unless ptos_list.all? { |pto| pto.is_a?(Domain::Pto) }

  ptos_list.reduce("") do |payload, pto|
    built_template = build_template(Domain::Pto::ATTRIBUTES, pto)
    payload + format_message_by_case(built_template.gsub("\n", ""), pto)
  end
end