Sha256: acedffed17643dd92bdaed56e0a4143571672f92f99f76ce4f19f1819fb62a9d

Contents?: true

Size: 847 Bytes

Versions: 1

Compression:

Stored size: 847 Bytes

Contents

module Csv2hash::Parser::Collection
  include Csv2hash::Parser

  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.options.fetch(:ignore_blank_line) and line.compact.empty?
        data_computed[:data] << {}.tap do |data_parsed|
          fill_it data_parsed, line
        end
      end
    end
  end

  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

end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
csv2hash-0.5.0 lib/csv2hash/parser/collection.rb