Sha256: baa99bb92531a24d675ee0a6a7d3d33df0acdef726f7e5faba0e58605f2a8685

Contents?: true

Size: 752 Bytes

Versions: 10

Compression:

Stored size: 752 Bytes

Contents

require 'time'

module Notifications
  class Client
    class Template
      FIELDS = %i(
        id
        type
        name
        created_at
        updated_at
        created_by
        version
        body
        subject
      ).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

10 entries across 10 versions & 1 rubygems

Version Path
notifications-ruby-client-5.2.0 lib/notifications/client/response_template.rb
notifications-ruby-client-5.1.2 lib/notifications/client/response_template.rb
notifications-ruby-client-5.1.1 lib/notifications/client/response_template.rb
notifications-ruby-client-5.1.0 lib/notifications/client/response_template.rb
notifications-ruby-client-4.0.0 lib/notifications/client/response_template.rb
notifications-ruby-client-3.1.0 lib/notifications/client/response_template.rb
notifications-ruby-client-3.0.0 lib/notifications/client/response_template.rb
notifications-ruby-client-2.10.0 lib/notifications/client/response_template.rb
notifications-ruby-client-2.9.0 lib/notifications/client/response_template.rb
notifications-ruby-client-2.8.0 lib/notifications/client/response_template.rb