6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
|
# File 'lib/cards_csv_importer.rb', line 6
def import(file)
raise ArgumentError.new("Invalid File. File should not be nil.") unless (! file.nil?())
@create_objects = Array.new()
@errors = Array.new()
@row_count=0
CSV::Reader.parse(file) do |row|
@row_count += 1
if (TITLE != row)
if (row.size() == TITLE.size())
parsed_row = parse_row(row, @row_count, @errors)
@create_objects = @create_objects + parsed_row
else
@errors<< "line #{@row_count.to_s()} is invalid (expected #{TITLE.size().to_s()} cells, found #{row.size().to_s()})\n#{row.join(',')}"
end
end
end
raise ArgumentError.new("Failed parsing:\n\t #{@errors.join('\n\t')}") unless @errors.empty?()
return @create_objects
end
|