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.49 lib/access/offer.rb
access-2.0.48 lib/access/offer.rb
access-2.0.47 lib/access/offer.rb
access-2.0.46 lib/access/offer.rb
access-2.0.44 lib/access/offer.rb
access-2.0.43 lib/access/offer.rb
access-2.0.42 lib/access/offer.rb
access-2.0.41 lib/access/offer.rb
access-2.0.40 lib/access/offer.rb
access-2.0.39 lib/access/offer.rb
access-2.0.38 lib/access/offer.rb
access-2.0.37 lib/access/offer.rb
access-2.0.36 lib/access/offer.rb
access-2.0.34 lib/access/offer.rb
access-2.0.33 lib/access/offer.rb
access-2.0.32 lib/access/offer.rb
access-2.0.31 lib/access/offer.rb
access-2.0.30 lib/access/offer.rb
access-2.0.29 lib/access/offer.rb
access-2.0.28 lib/access/offer.rb