lib/bill_hicks/inventory.rb in bill_hicks-1.3.6 vs lib/bill_hicks/inventory.rb in bill_hicks-1.3.7

- old
+ new

@@ -50,23 +50,26 @@ # Streams csv and chunks it # # @size integer The number of items in each chunk def process_as_chunks(size, &block) connect(@options) do |ftp| - temp_csv_file = Tempfile.new + tempfile = Tempfile.new ftp.chdir(BillHicks.config.top_level_dir) - ftp.getbinaryfile(INVENTORY_FILENAME, temp_csv_file.path) + ftp.getbinaryfile(INVENTORY_FILENAME, tempfile.path) - SmarterCSV.process(temp_csv_file, { :chunk_size => size, :force_utf8 => true, :convert_values_to_numeric => false, }) do |chunk| - chunk.each do |item| - item[:brand_name] = BillHicks::BrandConverter.convert(item[:product]) - end + smart_options = { + chunk_size: size, + key_mapping: { qty_avail: :quantity }, + force_utf8: true, + convert_values_to_numeric: false + } + SmarterCSV.process(tempfile, smart_options) do |chunk| yield(chunk) end - temp_csv_file.unlink + tempfile.unlink end end end end