Sha256: c2144bd93fc1614e05c49556d4f43d8bd2404558b9df9a2ca14c10d5ba984e7b

Contents?: true

Size: 810 Bytes

Versions: 10

Compression:

Stored size: 810 Bytes

Contents

module Csv2hash
  module Parser
    module Mapping
      include 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
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
csv2hash-0.7.2 lib/csv2hash/parser/mapping.rb
csv2hash-0.7.1 lib/csv2hash/parser/mapping.rb
csv2hash-0.7.0 lib/csv2hash/parser/mapping.rb
csv2hash-0.6.8 lib/csv2hash/parser/mapping.rb
csv2hash-0.6.7 lib/csv2hash/parser/mapping.rb
csv2hash-0.6.6 lib/csv2hash/parser/mapping.rb
csv2hash-0.6.5 lib/csv2hash/parser/mapping.rb
csv2hash-0.6.4 lib/csv2hash/parser/mapping.rb
csv2hash-0.6.3 lib/csv2hash/parser/mapping.rb
csv2hash-0.6.2 lib/csv2hash/parser/mapping.rb