Module: Csv2hash::Parser::Collection
- Includes:
- Expectation, Csv2hash::Parser
- Defined in:
- lib/csv2hash/parser/collection.rb
Instance Method Summary (collapse)
Methods included from Expectation
Instance Method Details
- (Object) fill!
9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/csv2hash/parser/collection.rb', line 9 def fill! self.data = {}.tap do |data_computed| data_computed[:data] ||= [] self.data_source.each_with_index do |line, y| next if unexpected_line?(line, y) data_computed[:data] << {}.tap do |data_parsed| fill_it data_parsed, line end end end end |
- (Object) fill_it(parsed_data, source_data)
21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/csv2hash/parser/collection.rb', line 21 def fill_it parsed_data, source_data definition.cells.each do |cell| if cell.rules.fetch :mappable x = cell.rules.fetch :position if (nested = cell.rules.fetch :nested) parsed_data[nested] ||= {} parsed_data[nested][cell.rules.fetch(:key)] = source_data[x] else parsed_data[cell.rules.fetch(:key)] = source_data[x] end end end end |