Sha256: 06ee6166358485e6a5002c513d1b449cb6ecff22358e75070a7027bd4c94338b

Contents?: true

Size: 984 Bytes

Versions: 10

Compression:

Stored size: 984 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
        postage
        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

10 entries across 10 versions & 1 rubygems

Version Path
notifications-ruby-client-6.0.0 lib/notifications/client/notification.rb
notifications-ruby-client-5.4.0 lib/notifications/client/notification.rb
notifications-ruby-client-5.3.0 lib/notifications/client/notification.rb
notifications-ruby-client-5.2.0 lib/notifications/client/notification.rb
notifications-ruby-client-5.1.2 lib/notifications/client/notification.rb
notifications-ruby-client-5.1.1 lib/notifications/client/notification.rb
notifications-ruby-client-5.1.0 lib/notifications/client/notification.rb
notifications-ruby-client-4.0.0 lib/notifications/client/notification.rb
notifications-ruby-client-3.1.0 lib/notifications/client/notification.rb
notifications-ruby-client-3.0.0 lib/notifications/client/notification.rb