Class: Zanders::Inventory
Constant Summary collapse
- INVENTORY_FILENAME =
"liveinv.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.
6 7 8 9 10 |
# File 'lib/zanders/inventory.rb', line 6 def initialize( = {}) requires!(, :username, :password) = end |
Class Method Details
.all(chunk_size = 15, options = {}, &block) ⇒ Object
12 13 14 15 |
# File 'lib/zanders/inventory.rb', line 12 def self.all(chunk_size = 15, = {}, &block) requires!(, :username, :password) new().all(chunk_size, &block) end |
Instance Method Details
#all(chunk_size, &block) ⇒ Object
17 18 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 |
# File 'lib/zanders/inventory.rb', line 17 def all(chunk_size, &block) connect() do |ftp| begin csv_tempfile = Tempfile.new ftp.chdir(Zanders.config.ftp_directory) ftp.getbinaryfile(INVENTORY_FILENAME, csv_tempfile.path) SmarterCSV.process(csv_tempfile, { chunk_size: chunk_size, convert_values_to_numeric: false, key_mapping: { available: :quantity, itemnumber: :item_identifier, price1: :price } }) do |chunk| chunk.each do |item| item.except!(:qty1, :qty2, :qty3, :price2, :price3) end yield(chunk) end csv_tempfile.unlink ensure ftp.close end end end |