Skip to content

Commit 1f709d9

Browse files
Arjan van der GaagArjan van der Gaag
Arjan van der Gaag
authored and
Arjan van der Gaag
committed
Parse price info into products
1 parent a4630ca commit 1f709d9

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

lib/bol/parsers/products.rb

+11
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,17 @@ def parse_object(el)
1515
product.attributes[field.to_sym] = el.at(_field).content.gsub(/\n\s+/, ' ').strip
1616
end
1717
end
18+
product[:offers] = []
19+
el.at('Offers').elements.each do |offer|
20+
o = %w[id first_edition special_edition state price list_price availability_code availability_description comment second_hand seller].inject({}) do |output, field|
21+
_field = camelize(field)
22+
if offer.at(_field)
23+
output[field] = offer.at(_field).content.gsub(/\n\s+/, ' ').strip
24+
end
25+
output
26+
end
27+
product[:offers] << OpenStruct.new(o)
28+
end
1829
product[:url] = el.at('Urls').at('Main').content.strip
1930
if el.at('ReleaseDate')
2031
product[:release_date] = Time.parse(el.at('ReleaseDate').content)

spec/bol/parsers/products_spec.rb

+8
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,14 @@
3333
product.release_date.day.should == 1
3434
end
3535

36+
it 'should parse offers' do
37+
product.offers.first.state.should == 'new'
38+
product.offers.first.price.should == '70.99'
39+
product.offers.first.list_price.should == '78.99'
40+
product.offers.first.availability_code.should == '167'
41+
product.offers.first.availability_description.should == '5-10 werkdagen'
42+
end
43+
3644
it 'should parse cover' do
3745
product.cover.should == 'http://s-bol.com/imgbase0/imagebase/thumb/FC/8/4/4/6/1001004006016448.jpg'
3846
product.cover(:medium).should == 'http://s-bol.com/imgbase0/imagebase/thumb/FC/8/4/4/6/1001004006016448.jpg'

0 commit comments

Comments
 (0)