Class: MgeWholesale::Inventory
- Defined in:
- lib/mge_wholesale/inventory.rb
Constant Summary collapse
- INVENTORY_FILENAME =
'exportXML_cq_barcodeFFL.csv'.freeze
- FULL_INVENTORY_FILENAME =
'exportXML_cq_barcodeFFL_all.csv'.freeze
Class Method Summary collapse
Instance Method Summary collapse
- #all(&block) ⇒ Object
-
#initialize(options = {}) ⇒ Inventory
constructor
A new instance of Inventory.
- #quantity(&block) ⇒ Object
Methods inherited from Base
Constructor Details
#initialize(options = {}) ⇒ Inventory
Returns a new instance of Inventory.
7 8 9 10 |
# File 'lib/mge_wholesale/inventory.rb', line 7 def initialize( = {}) requires!(, :username, :password) = end |
Class Method Details
.all(options = {}, &block) ⇒ Object
12 13 14 15 |
# File 'lib/mge_wholesale/inventory.rb', line 12 def self.all( = {}, &block) requires!(, :username, :password) new().all(&block) end |
.quantity(options = {}, &block) ⇒ Object
17 18 19 20 |
# File 'lib/mge_wholesale/inventory.rb', line 17 def self.quantity( = {}, &block) requires!(, :username, :password) new().quantity(&block) end |
Instance Method Details
#all(&block) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/mge_wholesale/inventory.rb', line 22 def all(&block) tempfile = get_file(INVENTORY_FILENAME) CSV.foreach(tempfile, { headers: :first_row }).each do |row| item = { item_identifier: row['id'], quantity: row['qty'].to_i, price: row['cost'], } yield(item) end tempfile.unlink end |
#quantity(&block) ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/mge_wholesale/inventory.rb', line 38 def quantity(&block) tempfile = get_file(FULL_INVENTORY_FILENAME) CSV.foreach(tempfile, { headers: :first_row }).each do |row| item = { item_identifier: row['id'], quantity: row['qty'].to_i, } yield(item) end tempfile.unlink end |