|
|
|
@ -24,7 +24,6 @@ class BulkUpload::Lettings::CsvParser |
|
|
|
stripped_row = row[1..] |
|
|
|
stripped_row = row[1..] |
|
|
|
headers = ("field_1".."field_134").to_a |
|
|
|
headers = ("field_1".."field_134").to_a |
|
|
|
hash = Hash[headers.zip(stripped_row)] |
|
|
|
hash = Hash[headers.zip(stripped_row)] |
|
|
|
# hash[:bulk_upload] = bulk_upload |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
BulkUpload::Lettings::RowParser.new(hash) |
|
|
|
BulkUpload::Lettings::RowParser.new(hash) |
|
|
|
end |
|
|
|
end |
|
|
|
@ -35,24 +34,21 @@ class BulkUpload::Lettings::CsvParser |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
def rows |
|
|
|
def rows |
|
|
|
@rows ||= CSV.read(path, row_sep:) |
|
|
|
@rows ||= CSV.parse(normalised_string, row_sep:) |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
private |
|
|
|
private |
|
|
|
|
|
|
|
|
|
|
|
# determine the row seperator from CSV |
|
|
|
|
|
|
|
# Windows will use \r\n |
|
|
|
|
|
|
|
def row_sep |
|
|
|
def row_sep |
|
|
|
contents = "" |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
File.open(path, "r") do |f| |
|
|
|
|
|
|
|
contents = f.read |
|
|
|
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if contents[-2..] == "\r\n" |
|
|
|
|
|
|
|
"\r\n" |
|
|
|
|
|
|
|
else |
|
|
|
|
|
|
|
"\n" |
|
|
|
"\n" |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def normalised_string |
|
|
|
|
|
|
|
return @normalised_string if @normalised_string |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@normalised_string = File.read(path) |
|
|
|
|
|
|
|
@normalised_string.gsub!("\r\n", "\n") |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@normalised_string |
|
|
|
end |
|
|
|
end |
|
|
|
end |
|
|
|
end |
|
|
|
|