lib/iron/import/importer.rb in iron-import-0.8.0 vs lib/iron/import/importer.rb in iron-import-0.8.1
- old
+ new
@@ -341,11 +341,11 @@
@reader = DataReader::for_format(self, @format)
else
# Auto select
@reader = DataReader::for_source(self, path_or_stream)
- @format = @reader.format
+ @format = @reader.format if @reader
end
# Verify we got one
unless @reader
add_error("Unable to find format handler for format :#{format} on import of #{path_or_stream.class.name} source - aborting")
@@ -421,11 +421,11 @@
def process
@data.rows.each do |row|
begin
yield row
rescue Exception => e
- add_error(row, e.to_s)
+ add_error(e.to_s, :row => row)
end
end
end
# Call with a block to process error handling tasks. Block will only execute
@@ -486,19 +486,19 @@
@missing_headers = []
return true
else
# Match by testing
- missing = nil
+ missing = []
raw_rows.each_with_index do |row, i|
# Um, have data?
next unless row
# Set up for this iteration
remaining = @columns.select {|c| !c.virtual? }
- # Step through this row's raw values, and look for a matching column for all columns
+ # Step through this row's raw values, and look for a matching header for all columns
row.each_with_index do |val, i|
val = val.to_s
col = remaining.detect {|c| c.match_header?(val, i) }
if col
remaining -= [col]
@@ -530,10 +530,12 @@
# Found all columns, have a map, update our start row to be the next line and return!
@data.start_row = @start_row || i+2
@missing_headers = []
return true
else
- missing = remaining if (missing.nil? || missing.count > remaining.count)
+ # Didn't find 'em all, remember this set of missing ones for reporting later
+ remaining.select! {|col| !col.optional? }
+ missing = remaining if missing.empty? || missing.count > remaining.count
end
end
# If we get here, we're hosed
@missing_headers = missing.collect(&:key) if @missing_headers.empty? || @missing_headers.count > missing.count