lib/csv2hash/parser/collection.rb in csv2hash-0.5.0 vs lib/csv2hash/parser/collection.rb in csv2hash-0.6.0
- old
+ new
@@ -1,31 +1,37 @@
-module Csv2hash::Parser::Collection
- include Csv2hash::Parser
+require_relative '../expectation'
- 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
+module Csv2hash
+ module Parser
+ module Collection
+ include Parser
+ include Expectation
+
+ def fill!
+ self.data = {}.tap do |data_computed|
+ data_computed[:data] ||= []
+ self.data_source.each_with_index do |line, y|
+ next if unexpected_line?(line, y)
+ data_computed[:data] << {}.tap do |data_parsed|
+ fill_it data_parsed, line
+ end
+ end
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]
+ def fill_it parsed_data, source_data
+ definition.cells.each do |cell|
+ if cell.rules.fetch :mappable
+ x = cell.rules.fetch :position
+ if (nested = cell.rules.fetch :nested)
+ parsed_data[nested] ||= {}
+ parsed_data[nested][cell.rules.fetch(:key)] = source_data[x]
+ else
+ parsed_data[cell.rules.fetch(:key)] = source_data[x]
+ end
+ end
end
end
+
end
end
-
end