Sha256: 2cbf24a93da501f6a9b3483d3528e7c252422c43ed7962c113a8871d75303223

Contents?: true

Size: 968 Bytes

Versions: 4

Compression:

Stored size: 968 Bytes

Contents

require 'time'

module Notifications
  class Client
    class Notification
      FIELDS = %i(
        id
        reference
        email_address
        phone_number
        line_1
        line_2
        line_3
        line_4
        line_5
        line_6
        postcode
        type
        status
        template
        body
        subject
        sent_at
        created_at
        completed_at
        created_by_name
      ).freeze

      attr_reader(*FIELDS)

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

      %i(
        sent_at
        created_at
        completed_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-2.10.0 lib/notifications/client/notification.rb
notifications-ruby-client-2.9.0 lib/notifications/client/notification.rb
notifications-ruby-client-2.8.0 lib/notifications/client/notification.rb
notifications-ruby-client-2.7.0 lib/notifications/client/notification.rb