Module: Csv2hash::Parser::Mapping
- Includes:
- Csv2hash::Parser
- Defined in:
- lib/csv2hash/parser/mapping.rb
Instance Method Summary collapse
Instance Method Details
#fill! ⇒ Object
4 5 6 7 8 9 10 11 |
# File 'lib/csv2hash/parser/mapping.rb', line 4 def fill! self.data = {}.tap do |data_computed| data_computed[:data] ||= [] data_computed[:data] << {}.tap do |data_parsed| fill_it data_parsed, data_source end end end |
#fill_it(parsed_data, source_data) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/csv2hash/parser/mapping.rb', line 13 def fill_it parsed_data, source_data definition.rules.each do |rule| if rule.fetch :mappable y, x = rule.fetch :position if (nested = rule.fetch :nested) parsed_data[nested] ||= {} parsed_data[nested][rule.fetch(:key)] = source_data[y][x] else parsed_data[rule.fetch(:key)] = source_data[y][x] end end end end |