Sha256: f402f77b58c7ebd5f5e4ac11658480775a8166cea9a7cc2ea8d8634207412126

Contents?: true

Size: 670 Bytes

Versions: 7

Compression:

Stored size: 670 Bytes

Contents

module Csv2hash::Parser::Mapping
  include Csv2hash::Parser

  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

  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

end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
csv2hash-0.5.0 lib/csv2hash/parser/mapping.rb
csv2hash-0.4.0 lib/csv2hash/parser/mapping.rb
csv2hash-0.3.0 lib/csv2hash/parser/mapping.rb
csv2hash-0.2.1 lib/csv2hash/parser/mapping.rb
csv2hash-0.2.0 lib/csv2hash/parser/mapping.rb
csv2hash-0.1.1 lib/csv2hash/parser/mapping.rb
csv2hash-0.1 lib/csv2hash/parser/mapping.rb