Class: Davidsons::Inventory
Constant Summary collapse
- WHOLE_CATALOG_FILENAME =
'davidsons_inventory.csv'.freeze
- DEFAULT_WHOLE_CATALOG_SMART_OPTS =
{ chunk_size: 500, convert_values_to_numeric: false, force_utf8: true, remove_unmapped_keys: true, key_mapping: { "item_#": :item_identifier, upc_code: :upc, msp: :msp, dealer_price: :dealer_price, sale_price: :sale_price, quantity: :quantity, } }
- QUANTITY_FILENAME =
'davidsons_quantity.csv'.freeze
- DEFAULT_QUANTITY_SMART_OPTS =
{ chunk_size: 2000, convert_values_to_numeric: false, force_utf8: true, key_mapping: { item_number: :item_identifier, upc_code: :upc } }
Class Method Summary collapse
-
.all(options = {}) ⇒ Object
Iterates over all items in the ‘davidsons_inventory.csv’ file yielding the item_identifier, quantity, and price.
-
.quantity(options = {}) ⇒ Object
Iterates over all items in the ‘davidsons_quantity.csv’ file yielding the item_identifier, upc, quantity and locations.
Instance Method Summary collapse
- #all ⇒ Object
-
#initialize(options = {}) ⇒ Inventory
constructor
A new instance of Inventory.
- #quantity ⇒ Object
Methods inherited from Base
Constructor Details
#initialize(options = {}) ⇒ Inventory
Returns a new instance of Inventory.
37 38 39 40 41 |
# File 'lib/davidsons/inventory.rb', line 37 def initialize( = {}) requires!(, :username, :password) @options = @options[:pricing_tier] ||= :regular end |
Class Method Details
.all(options = {}) ⇒ Object
Iterates over all items in the ‘davidsons_inventory.csv’ file yielding the item_identifier, quantity, and price. We have to use this file since the ‘davidsons_quantity.csv’ file does not included prices. The price can vary based on the pricing_tier
53 54 55 56 |
# File 'lib/davidsons/inventory.rb', line 53 def self.all( = {}) requires!(, :username, :password) new().all end |
.quantity(options = {}) ⇒ Object
Iterates over all items in the ‘davidsons_quantity.csv’ file yielding the item_identifier, upc, quantity and locations.
63 64 65 66 |
# File 'lib/davidsons/inventory.rb', line 63 def self.quantity( = {}) requires!(, :username, :password) new().quantity end |
Instance Method Details
#all ⇒ Object
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/davidsons/inventory.rb', line 68 def all items = [] tempfile = get_file(WHOLE_CATALOG_FILENAME) SmarterCSV.process(tempfile, DEFAULT_WHOLE_CATALOG_SMART_OPTS) do |chunk| chunk.each do |item| item[:upc]&.tr!('#', '') item[:price] = lowest_price(item) item[:quantity] = item[:quantity].to_i items << item end end items end |
#quantity ⇒ Object
86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 |
# File 'lib/davidsons/inventory.rb', line 86 def quantity items = [] tempfile = get_file(QUANTITY_FILENAME) SmarterCSV.process(tempfile, DEFAULT_QUANTITY_SMART_OPTS) do |chunk| chunk.each do |item| item[:quantity] = item[:quantity_nc].to_i + item[:quantity_az].to_i item[:locations] = map_location_quantities(item) items << item end end items end |