Sha256: 585032e6c61c39074c5fc603587ebca0537d2ec0d693050598b9d95fa12fb98b

Contents?: true

Size: 958 Bytes

Versions: 3

Compression:

Stored size: 958 Bytes

Contents

module Kosher
  class Offer < Struct.new(
    :seller,
    :condition,
    :description,
    :ships_in,
    :ships_free,
    :cents,
    :listing_id)

    def self.build(doc)
      offer             = new
      offer.seller      = Seller.build(doc['Merchant'])

      attributes        = doc['OfferAttributes']
      offer.condition   = Condition.new(attributes['SubCondition'])
      offer.description = Description.new(attributes['ConditionNote'].to_s)

      listing           = doc['OfferListing']
      offer.ships_in    = listing['AvailabilityAttributes']['MaximumHours'].to_i
      offer.ships_free  = listing['IsEligibleForSuperSaverShipping'] == '1'
      offer.cents       = listing['Price']['Amount'].to_i
      offer.listing_id  = listing['OfferListingId']

      offer
    end

    def kosher?
      condition.kosher? && seller.kosher? && description.kosher? && ships_now?
    end

    def ships_now?
      ships_in.to_i <= 48
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
kosher-0.1.9 lib/kosher/offer.rb
kosher-0.1.8 lib/kosher/offer.rb
kosher-0.1.7 lib/kosher/offer.rb