Class: BillHicks::Catalog
Overview
Catalog item response structure:
{
product_name: "...",
upc: "...",
short_description: "...",
long_description: "...",
category: "...",
price: "...",
weight: "...",
map: "...",
msrp: "...",
}
Constant Summary collapse
- CHUNK_SIZE =
500
- CATALOG_FILENAME =
'billhickscatalog.csv'.freeze
- PERMITTED_FEATURES =
[ 'weight', 'caliber', 'action', 'mount', 'finish', 'length', 'diameter', 'rail', 'trigger', 'barrel length', 'silencer mount', 'barrel', 'stock', 'internal bore', 'thread pitch', 'dimensions', 'bulb type', 'bezel diameter', 'output max', 'battery type', 'mount type', 'waterproof rating', 'operating temperature' ]
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.
45 46 47 48 |
# File 'lib/bill_hicks/catalog.rb', line 45 def initialize( = {}) requires!(, :username, :password) = end |
Class Method Details
.all(options = {}) ⇒ Object
50 51 52 53 |
# File 'lib/bill_hicks/catalog.rb', line 50 def self.all( = {}) requires!(, :username, :password) new().all end |
Instance Method Details
#all ⇒ Object
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 |
# File 'lib/bill_hicks/catalog.rb', line 55 def all items = [] connect() do |ftp| tempfile = Tempfile.new ftp.chdir(BillHicks.config.top_level_dir) ftp.getbinaryfile(CATALOG_FILENAME, tempfile.path) SmarterCSV.process(tempfile, { chunk_size: CHUNK_SIZE, force_utf8: true, convert_values_to_numeric: false, key_mapping: { universal_product_code: :upc, product_name: :name, product_weight: :weight, product_price: :price, category_description: :category, marp: :map_price, } }) do |chunk| chunk.each do |item| item.except!(:category_code) item[:item_identifier] = item[:name] item[:brand] = BillHicks::BrandConverter.convert(item[:name]) item[:mfg_number] = item[:name].split.last if item[:long_description].present? features = parse_features(item[:long_description]) item[:action] = features.delete(:action) if features[:action].present? item[:caliber] = features.delete(:caliber) if features[:caliber].present? item[:weight] = features.delete(:weight) if features[:weight].present? item[:features] = features end items << item end end tempfile.unlink end items end |