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