Sha256: 2295de3aa9158908fc851e3ca6244cea28783e37e3c3718b7d98dd7c72c84ec3

Contents?: true

Size: 776 Bytes

Versions: 2

Compression:

Stored size: 776 Bytes

Contents

module KB
  class Product < BaseModel
    include Listable
    include Findable

    kb_api :product

    def self.by_country(country)
      all(country: country)
    end

    def self.attributes_from_response(response)
      response.transform_keys(&:underscore).transform_keys(&:to_sym).slice(*FIELDS)
    end

    private_class_method :attributes_from_response

    STRING_FIELDS = %i[key country name type].freeze
    STRING_ARRAY_FIELDS = %i[exclusions inclusions features claimable_by languages].freeze
    FIELDS = [*STRING_FIELDS, *STRING_ARRAY_FIELDS, :purchasable].freeze

    define_attribute_methods(*FIELDS)

    attribute :purchasable, :boolean

    define_attributes STRING_FIELDS, :string
    define_attributes STRING_ARRAY_FIELDS, :array_of_strings
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
barkibu-kb-0.27.0 lib/kb/models/product.rb
barkibu-kb-0.26.0 lib/kb/models/product.rb