Sha256: fa0d4ef7c086fbefa5c0b88f997989679b9335cf1ee9423f348ddc308093ca88

Contents?: true

Size: 781 Bytes

Versions: 4

Compression:

Stored size: 781 Bytes

Contents

require 'time'

module Notifications
  class Client
    class Template
      FIELDS = %i(
        id
        type
        name
        created_at
        updated_at
        created_by
        version
        body
        subject
        letter_contact_block
      ).freeze

      attr_reader(*FIELDS)

      def initialize(notification)
        FIELDS.each do |field|
          instance_variable_set(:"@#{field}", notification.fetch(field.to_s, nil))
        end
      end

      %i(
        created_at
        updated_at
      ).each do |field|
        define_method field do
          begin
            value = instance_variable_get(:"@#{field}")
            Time.parse value
          rescue StandardError
            value
          end
        end
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
notifications-ruby-client-6.2.0 lib/notifications/client/response_template.rb
notifications-ruby-client-6.0.0 lib/notifications/client/response_template.rb
notifications-ruby-client-5.4.0 lib/notifications/client/response_template.rb
notifications-ruby-client-5.3.0 lib/notifications/client/response_template.rb