Class: BillHicks::Inventory
Overview
Inventory item response structure:
{
product: "...",
upc: "...",
quantity: "..."
}
Constant Summary collapse
- CHUNK_SIZE =
2000
- INVENTORY_FILENAME =
'billhicksinventory.csv'
Class Method Summary collapse
- .all(options = {}) ⇒ Object
- .get_quantity_file(options = {}) ⇒ Object
- .quantity(options = {}) ⇒ Object
Instance Method Summary collapse
- #all ⇒ Object (also: #quantity)
- #get_quantity_file ⇒ 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.
14 15 16 17 |
# File 'lib/bill_hicks/inventory.rb', line 14 def initialize( = {}) requires!(, :username, :password) @options = end |
Class Method Details
.all(options = {}) ⇒ Object
29 30 31 32 |
# File 'lib/bill_hicks/inventory.rb', line 29 def self.all( = {}) requires!(, :username, :password) new().all end |
.get_quantity_file(options = {}) ⇒ Object
19 20 21 22 |
# File 'lib/bill_hicks/inventory.rb', line 19 def self.get_quantity_file( = {}) requires!(, :username, :password) new().get_quantity_file end |
.quantity(options = {}) ⇒ Object
24 25 26 27 |
# File 'lib/bill_hicks/inventory.rb', line 24 def self.quantity( = {}) requires!(, :username, :password) new().all end |
Instance Method Details
#all ⇒ Object Also known as: quantity
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/bill_hicks/inventory.rb', line 34 def all items = [] quantity_tempfile = get_file(INVENTORY_FILENAME) SmarterCSV.process(quantity_tempfile, { chunk_size: CHUNK_SIZE, force_utf8: true, convert_values_to_numeric: false, key_mapping: { product: :item_identifier, qty_avail: :quantity, } }) do |chunk| chunk.each do |item| items << item end end quantity_tempfile.close quantity_tempfile.unlink items end |
#get_quantity_file ⇒ Object
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/bill_hicks/inventory.rb', line 58 def get_quantity_file quantity_tempfile = get_file(INVENTORY_FILENAME) tempfile = Tempfile.new SmarterCSV.process(quantity_tempfile, { chunk_size: CHUNK_SIZE, force_utf8: true, convert_values_to_numeric: false, key_mapping: { product: :item_identifier, qty_avail: :quantity, } }) do |chunk| chunk.each do |item| tempfile.puts("#{item[:item_identifier]},#{item[:quantity]}") end end quantity_tempfile.close quantity_tempfile.unlink tempfile.close tempfile.path end |