lib/barnie/response.rb in barnie-0.3.0 vs lib/barnie/response.rb in barnie-0.3.1

- old
+ new

@@ -2,45 +2,34 @@ require 'barnie/helpers' module Barnie class Response include Helpers + include Enumerable attr_reader :page def initialize(page) raise Error.new('Blank page') if page.body.empty? && page.code == 200 @page = page end - # Yields each snapshot to given block. - # - def each - container.each { |html| yield parse(html) } + def each(&block) + page.search('#prod-container').each { |html| block.call(parse(html)) } end - # Returns an array of snapshots. - # - def to_a - container.map { |html| parse(html) } - end - private - def container - page.search('#prod-container') - end - def parse(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( + Kosher::Book.new( 'bn.com', isbn, nil, nil, price > 0 ? 1 : 0, @@ -50,9 +39,8 @@ 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