Sha256: e179e8d77a4dbcdeffa98c3b9277bd4612fff916f0afa44c94ef92ec377560fe

Contents?: true

Size: 790 Bytes

Versions: 7

Compression:

Stored size: 790 Bytes

Contents

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

    class << self
      def build(doc)
        asin         = doc['ASIN']
        sales_rank   = doc['SalesRank'].to_i
        offers_count = doc['Offers']['TotalOffers'].to_i
        offers       = build_offers(doc['Offers']['Offer'])

        new(asin, offers, offers_count, sales_rank)
      end

      private

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

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

          Offer.build(offer)
        end
      end
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
kosher-0.1.12 lib/kosher/item.rb
kosher-0.1.11 lib/kosher/item.rb
kosher-0.1.10 lib/kosher/item.rb
kosher-0.1.9 lib/kosher/item.rb
kosher-0.1.8 lib/kosher/item.rb
kosher-0.1.7 lib/kosher/item.rb
kosher-0.1.6 lib/kosher/item.rb