Class: Zanders::Inventory
Constant Summary collapse
- INVENTORY_FILENAME =
"liveinv.csv"- DEFAULT_SMART_OPTS =
{ convert_values_to_numeric: false, key_mapping: { available: :quantity, itemnumber: :item_identifier }, remove_unmapped_keys: true }
Class Method Summary collapse
- .all(chunk_size = 100, options = {}, &block) ⇒ Object
- .quantity(chunk_size = 100, options = {}, &block) ⇒ Object
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.
15 16 17 18 19 |
# File 'lib/zanders/inventory.rb', line 15 def initialize( = {}) requires!(, :username, :password) @options = end |
Class Method Details
.all(chunk_size = 100, options = {}, &block) ⇒ Object
21 22 23 24 |
# File 'lib/zanders/inventory.rb', line 21 def self.all(chunk_size = 100, = {}, &block) requires!(, :username, :password) new().all(chunk_size, &block) end |
.quantity(chunk_size = 100, options = {}, &block) ⇒ Object
26 27 28 29 |
# File 'lib/zanders/inventory.rb', line 26 def self.quantity(chunk_size = 100, = {}, &block) requires!(, :username, :password) new().all(chunk_size, &block) end |
Instance Method Details
#all(chunk_size, &block) ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/zanders/inventory.rb', line 31 def all(chunk_size, &block) connect(@options) do |ftp| begin csv_tempfile = Tempfile.new ftp.chdir(Zanders.config.ftp_directory) ftp.getbinaryfile(INVENTORY_FILENAME, csv_tempfile.path) opts = DEFAULT_SMART_OPTS.merge(chunk_size: chunk_size) SmarterCSV.process(csv_tempfile, opts) do |chunk| yield(chunk) end csv_tempfile.unlink ensure ftp.close end end end |