Sha256: df485be3f166bc1033305319060b08e5ccfa4408e7e83d3be157f7acf25752c4

Contents?: true

Size: 833 Bytes

Versions: 12

Compression:

Stored size: 833 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

    STRING_FIELDS.each do |field|
      attribute field, :string
    end

    STRING_ARRAY_FIELDS.each do |field|
      attribute field, :array_of_strings
    end
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
barkibu-kb-0.25.0 lib/kb/models/product.rb
barkibu-kb-0.24.1 lib/kb/models/product.rb
barkibu-kb-0.24.0 lib/kb/models/product.rb
barkibu-kb-0.23.0 lib/kb/models/product.rb
barkibu-kb-0.22.0 lib/kb/models/product.rb
barkibu-kb-0.21.0 lib/kb/models/product.rb
barkibu-kb-0.20.0 lib/kb/models/product.rb
barkibu-kb-0.19.0 lib/kb/models/product.rb
barkibu-kb-0.18.0 lib/kb/models/product.rb
barkibu-kb-0.17.0 lib/kb/models/product.rb
barkibu-kb-0.16.2 lib/kb/models/product.rb
barkibu-kb-0.16.1 lib/kb/models/product.rb