require 'kosher' require 'barnie/helpers' module Barnie class Response include Helpers attr_accessor :page def initialize(page) self.page = page end def snapshots raise Error.new('Blank page') if page.body == '' && page.code == 200 container = page.search('#prod-container') container.map do |html| price = extract_price(html.search('.price strong').text) hours = extract_ships_in(html.search('.availability').text) || 999 title = title(html) link = extract_link(title) isbn = extract_isbn(link) Kosher::Snapshot.new( 'bn.com', isbn, nil, nil, price > 0 ? 1 : 0, price > 0 ? [Kosher::Offer.new( nil, Kosher::Item.new(price, 'USD', 1, Kosher::Condition.new(1), Kosher::Description.new('')), Kosher::Seller.new(nil, 'Barnes & Noble.com', nil, Kosher::Location.new('US')), Kosher::Shipping.new(0, 'USD', Kosher::Availability.new(hours)) )] : []) end end end end