Sha256: 00e7f7288f7ab868348b13d8780d5d3490a451caed370cab0b9083935c0bc471

Contents?: true

Size: 548 Bytes

Versions: 3

Compression:

Stored size: 548 Bytes

Contents

module Kosher
  class Item < Struct.new(:asin, :offers)

    def self.build(doc)
      asin   = doc['ASIN']
      offers = build_offers(doc['Offers']['Offer'])

      new(asin, offers)
    end

    private

    def self.build_offers(offers)
      [offers].flatten.compact.map do |offer|

        # Senify Yen because Ruby Money says so
        price = offer['OfferListing']['Price']
        if price['CurrencyCode'] == 'JPY'
          price['Amount'] = price['Amount'].to_i * 100
        end

        Offer.build(offer)
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
kosher-0.1.2 lib/kosher/item.rb
kosher-0.1.1 lib/kosher/item.rb
kosher-0.1.0 lib/kosher/item.rb