Sha256: 6a21773fc2f4633ba80fa1cd3124187747169b7f8486daf80d9e257786db95b1

Contents?: true

Size: 866 Bytes

Versions: 12

Compression:

Stored size: 866 Bytes

Contents

module KB
  class Breed < BaseModel
    include Listable

    DEFAULT_LOCALE = ENV.fetch('KB_BREEDS_DEFAULT_LOCALE', 'es-es')

    kb_api :breed

    def self.all(filters = {})
      filters[:locale] ||= DEFAULT_LOCALE
      super(filters)
    end

    def self.dogs(filters = {})
      filters[:species] = 'dog'
      all(filters)
    end

    def self.cats(filters = {})
      filters[:species] = 'cat'
      all(filters)
    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 locale name species weight_group external_id].freeze
    FIELDS = [*STRING_FIELDS].freeze

    define_attribute_methods(*FIELDS)

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

Version data entries

12 entries across 12 versions & 1 rubygems

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