19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
|
# File 'lib/lipseys/catalog.rb', line 19
def all
inventory_tempfile = stream_to_tempfile(Lipseys::Inventory::API_URL, @options)
catalog_tempfile = stream_to_tempfile(API_URL, @options)
inventory = []
items = []
Lipseys::Parser.parse(inventory_tempfile, 'Item') do |node|
inventory.push({
item_identifier: content_for(node, 'ItemNo'),
map_price: content_for(node, 'RetailMAP'),
quantity: content_for(node, 'QtyOnHand'),
price: content_for(node, 'Price')
})
end
Lipseys::Parser.parse(catalog_tempfile, 'Item') do |node|
item = map_hash(node)
availability = inventory.select { |i| i[:item_identifier] == item[:item_identifier] }.first
if availability
item[:price] = availability[:price]
item[:quantity] = availability[:quantity]
item[:map_price] = availability[:map_price]
end
items << item
end
inventory_tempfile.unlink
catalog_tempfile.unlink
items
end
|