Sha256: 8dd744a2704861c528cbf30ac573a3abb4fe6ac58bf0652ae5b072e1a7e1cac3

Contents?: true

Size: 1.09 KB

Versions: 26

Compression:

Stored size: 1.09 KB

Contents

module Access
  class Offer
    attr_reader :store, :location

    def self.search(options = {})
      Access::Api.new.search_offers options
    end

    def self.find(offer_key, options = {})
      Access::Api.new.find_offer offer_key, options
    end

    def self.find_uses_remaining(offer_key, options = {})
      Access::Api.new.find_offer_uses_remaining offer_key, options
    end

    def self.process_batch(chunk)
      chunk.map { |offer| new(offer) }
    end

    def initialize(values)
      self.class.class_eval { attr_reader *values.keys }
      values.each do |attribute_name, attribute_value|
        self.instance_variable_set("@#{attribute_name}", attribute_value)
      end
      @categories = Access::Category.process_batch(@categories) if @categories
      @links = Access::Link.new(@links) if @links
      @offer_store = Access::Store.new(@offer_store) if @offer_store
      @offer_uses_remaining = Access::Redemption.new(@offer_uses_remaining) if @offer_uses_remaining
    end

    def location
      @offer_store.physical_location
    end

    def store
      @offer_store
    end
  end
end

Version data entries

26 entries across 26 versions & 1 rubygems

Version Path
access-2.0.27 lib/access/offer.rb
access-2.0.26 lib/access/offer.rb
access-2.0.25 lib/access/offer.rb
access-2.0.24 lib/access/offer.rb
access-2.0.23 lib/access/offer.rb
access-2.0.22 lib/access/offer.rb