Module: Squib::Import::QuantityExploder

Included in:
CsvImporter, XlsxImporter, YamlImporter
Defined in:
lib/squib/import/quantity_exploder.rb

Instance Method Summary collapse

Instance Method Details

#explode_quantities(data, qty) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
# File 'lib/squib/import/quantity_exploder.rb', line 4

def explode_quantities(data, qty)
  return data unless data.col? qty.to_s.strip
  qtys = data[qty]
  new_data = Squib::DataFrame.new
  data.each do |col, arr|
    new_data[col] = []
    qtys.each_with_index do |qty, index|
      qty.to_i.times { new_data[col] << arr[index] }
    end
  end
  return new_data
end