Sha256: eb57eb5572b7932afe4eb536529a2eb9367f0ce6e5eeeef10a0d92e12f82aef1

Contents?: true

Size: 700 Bytes

Versions: 2

Compression:

Stored size: 700 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.cells.each do |cell|
      if cell.rules.fetch :mappable
        y, x = cell.rules.fetch :position
        if (nested = cell.rules.fetch :nested)
          parsed_data[nested] ||= {}
          parsed_data[nested][cell.rules.fetch(:key)] = source_data[y][x]
        else
          parsed_data[cell.rules.fetch(:key)] = source_data[y][x]
        end
      end
    end
  end

end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
csv2hash-0.6.1 lib/csv2hash/parser/mapping.rb
csv2hash-0.6.0 lib/csv2hash/parser/mapping.rb