Class: BillHicks::Inventory
Overview
Inventory item response structure:
{
product: "...",
upc: "...",
quantity: "..."
}
Constant Summary collapse
- INVENTORY_FILENAME =
'billhicksinventory.csv'
Class Method Summary collapse
Instance Method Summary collapse
- #all(chunk_size, &block) ⇒ Object
-
#initialize(options = {}) ⇒ Inventory
constructor
A new instance of Inventory.
Methods inherited from Base
Constructor Details
#initialize(options = {}) ⇒ Inventory
Returns a new instance of Inventory.
13 14 15 16 |
# File 'lib/bill_hicks/inventory.rb', line 13 def initialize( = {}) requires!(, :username, :password) @options = end |
Class Method Details
.all(chunk_size = 15, options = {}, &block) ⇒ Object
18 19 20 21 |
# File 'lib/bill_hicks/inventory.rb', line 18 def self.all(chunk_size = 15, = {}, &block) requires!(, :username, :password) new().all(chunk_size, &block) end |
Instance Method Details
#all(chunk_size, &block) ⇒ Object
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 |
# File 'lib/bill_hicks/inventory.rb', line 23 def all(chunk_size, &block) connect(@options) do |ftp| begin csv_tempfile = Tempfile.new ftp.chdir(BillHicks.config.top_level_dir) ftp.getbinaryfile(INVENTORY_FILENAME, csv_tempfile.path) SmarterCSV.process(csv_tempfile, { chunk_size: chunk_size, force_utf8: true, convert_values_to_numeric: false, key_mapping: { qty_avail: :quantity, upc: :item_identifier } }) do |chunk| chunk.each do |item| item.except!(:product) end yield(chunk) end ensure ftp.close end end end |