@@ -24,8 +24,9 @@ def check input, output, mappings={}, csv_options={}, skip_first=false
2424 end
2525
2626 lines_scanned = lines_scanned + 1
27+ #print "line #{line_no}\n"
2728
28- check_against_mapping ( row , mappings )
29+ check_against_mapping ( row , mappings ) unless row . empty?
2930 end
3031
3132 print "Total number of lines checked: #{ lines_scanned } \n "
@@ -34,22 +35,29 @@ def check input, output, mappings={}, csv_options={}, skip_first=false
3435
3536
3637 def check_against_mapping row , mappings
37- row . each_index { |i |
38- if mappings [ i ] then
39- print "Checking col #{ i } \n "
38+ return if mappings . nil? || row . nil?
39+
40+ i = 0
41+ row . each { |item |
42+ type = mappings [ i . to_s ]
43+
44+ if type then
45+ print "Checking col #{ i } against type #{ type } \n "
46+ raise "Error at col #{ i } " unless analyse_column item , type
4047 end
41- }
48+
49+ i = i + 1
50+ }
4251 end
4352
4453
45- def analyse_column row , index , type
46- raise 'Nil row ' unless row
47- raise 'Empty row ' unless row . size > 0
48- raise 'Nil index ' unless index
49- raise 'Negative index ' unless index >= 0
54+ def analyse_column cell , type
55+ raise 'Nil cell ' unless cell
56+ raise 'Empty cell ' unless cell . size > 0
57+ raise 'Nil type ' unless type
58+ raise 'Empty type ' unless type . size > 0
5059
5160 type . downcase!
52- cell = row [ index ]
5361
5462 case type
5563 when 'integer'
0 commit comments