bin/csv-validator in csv-utils-0.3.8 vs bin/csv-validator in csv-utils-0.3.9
- old
+ new
@@ -33,24 +33,28 @@
id_column_name = ARGV[1]
headers = csv.shift
strip_bom!(headers[0])
-id_column_num = nil
-if id_column_name
- unless headers.include?(id_column_name)
- $stderr.puts("header #{id_column_name} not found in current set of headers")
- exit 1
- end
-
- id_column_num = headers.index(id_column_name)
+id_column_name ||= headers[0]
+unless headers.include?(id_column_name)
+ $stderr.puts("header #{id_column_name} not found in current set of headers")
+ exit 1
end
+id_column_num = headers.index(id_column_name)
+
out = nil
-if id_column_num
- out = CSV.open('utf8-correctsion.csv', 'wb')
- out << [id_column_name, 'Row', 'Col', 'Header', 'Value']
+out_proc = Proc.new do |row|
+ out ||=
+ begin
+ out = CSV.open('utf8-correctsion.csv', 'wb')
+ out << [id_column_name, 'Row', 'Col', 'Header', 'Value']
+ out
+ end
+
+ out << row
end
csv_lineno = 1
while (row = csv.shift)
@@ -64,10 +68,10 @@
next if col.nil? || utf8?(col)
$stderr.puts "row(#{csv_lineno}),col(#{idx + 1}) #{headers[idx]}: none UTF-8 characters found in \"#{col}\""
if (col_utf8_encoded = convert_to_utf8(col, detect_encoding(col)))
puts "row(#{csv_lineno}),col(#{idx + 1}) #{headers[idx]}: converted to UTF-8 from #{detect_encoding(col)} \"#{col_utf8_encoded}\""
- out << [row[id_column_num], csv_lineno, (idx + 1), headers[idx], col_utf8_encoded]
+ out_proc.call [row[id_column_num], csv_lineno, (idx + 1), headers[idx], col_utf8_encoded]
else
$stderr.puts "row(#{csv_lineno}),col(#{idx + 1}) #{headers[idx]}: unknown character encoding"
end
end
end