Sha256: 53cd5ced62745674556650cb2472afcde1d2a0bae6eb5224872e7c67d5e9623f

Contents?: true

Size: 1.35 KB

Versions: 7

Compression:

Stored size: 1.35 KB

Contents

require 'fassbinder/item_builder'
require 'fassbinder/seller_builder'
require 'fassbinder/shipping_builder'

module Fassbinder
  class OfferBuilder
    attr_reader :offer

    def initialize
      @offer = Kosher::Offer.new
    end

    def add_item(hash)
      builder = ItemBuilder.new
      builder.price = hash['OfferListing']['Price']
      builder.quantity = hash['OfferListing']['Quantity']
      builder.add_condition(hash['OfferAttributes']['SubCondition'])
      builder.add_description(hash['OfferAttributes']['ConditionNote'])
      @offer.item = builder.item
    end

    def add_seller(hash)
      builder = SellerBuilder.new
      builder.id = hash['MerchantId']
      builder.name = hash['Name']
      builder.rating = hash['AverageFeedbackRating']
      builder.add_location(hash['Location']) if hash['Location']
      @offer.seller = builder.seller
    end

    def add_shipping(hash)
      builder = ShippingBuilder.new
      builder.add_availability(hash['OfferListing']['AvailabilityAttributes']['MaximumHours'])
      is_free = (hash['OfferListing']['IsEligibleForSuperSaverShipping'] == '1')
      builder.calculate_price(is_free, @offer.venue, hash['OfferListing']['Price']['CurrencyCode'])
      @offer.shipping = builder.shipping
    end

    def id=(id)
      @offer.id = id
    end

    def venue=(venue)
      @offer.venue = venue
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
fassbinder-0.0.15 lib/fassbinder/offer_builder.rb
fassbinder-0.0.14 lib/fassbinder/offer_builder.rb
fassbinder-0.0.13 lib/fassbinder/offer_builder.rb
fassbinder-0.0.12 lib/fassbinder/offer_builder.rb
fassbinder-0.0.11 lib/fassbinder/offer_builder.rb
fassbinder-0.0.10 lib/fassbinder/offer_builder.rb
fassbinder-0.0.9 lib/fassbinder/offer_builder.rb