Class: Davidsons::Catalog
Constant Summary collapse
- WHOLE_CATALOG_FILENAME =
'davidsons_inventory.csv'.freeze
- DEFAULT_SMART_OPTS =
{ chunk_size: 500, convert_values_to_numeric: false, force_utf8: true, key_mapping: { "item_#": :item_identifier, item_description: :name, upc_code: :upc, manufacturer: :brand, retail_price: :msrp, gun_type: :category, } }
Class Method Summary collapse
Instance Method Summary collapse
- #all ⇒ Object
-
#initialize(options = {}) ⇒ Catalog
constructor
A new instance of Catalog.
Methods inherited from Base
Constructor Details
#initialize(options = {}) ⇒ Catalog
Returns a new instance of Catalog.
25 26 27 28 29 |
# File 'lib/davidsons/catalog.rb', line 25 def initialize( = {}) requires!(, :username, :password) @options = @options[:pricing_tier] ||= :regular end |
Class Method Details
.all(options = {}) ⇒ Object
31 32 33 34 |
# File 'lib/davidsons/catalog.rb', line 31 def self.all( = {}) requires!(, :username, :password) new().all end |
Instance Method Details
#all ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/davidsons/catalog.rb', line 36 def all tempfile = get_file(WHOLE_CATALOG_FILENAME) items = [] SmarterCSV.process(tempfile, DEFAULT_SMART_OPTS) do |chunk| chunk.each do |item| item[:msrp]&.tr!('$', '') item[:upc]&.tr!('#', '') item[:price] = lowest_price(item) item[:mfg_number] = item[:item_identifier] item[:quantity] = item[:quantity].to_i item[:features] = map_features(item) item.delete(:sale_ends) item.delete(:sale_price) items << item end end tempfile.unlink items end |