lib/lipseys/inventory.rb in lipseys-2.0.8 vs lib/lipseys/inventory.rb in lipseys-2.0.9

- old
+ new

@@ -11,10 +11,14 @@ def self.all(chunk_size = 15, options = {}, &block) new(options).all(chunk_size, &block) end + def self.quantity(chunk_size = 100, options = {}, &block) + new(options).all(chunk_size, &block) + end + def self.accessories(options = {}) new(options).accessories end def self.firearms(options = {}) @@ -43,9 +47,32 @@ end # HACK-david # since we can't get a count of the items without reading the file # Let's just check to see if we have any left in the chunk + if chunker.chunk.count > 0 + yield(chunker.chunk) + end + + tempfile.unlink + end + + def quantity(size, &block) + chunker = Lipseys::Chunker.new(size) + tempfile = stream_to_tempfile(API_URL, @options) + + Lipseys::Parser.parse(tempfile, 'Item') do |node| + if chunker.is_full? + yield(chunker.chunk) + chunker.reset! + else + chunker.add({ + item_identifier: content_for(node, 'ItemNo'), + quantity: content_for(node, 'QtyOnHand') + }) + end + end + if chunker.chunk.count > 0 yield(chunker.chunk) end tempfile.unlink