I have a client who wants to maintain a broad span of flexibility when submitting CSV files to be uploaded. I've been using SmarterCSV to process the files, but have hit a snag where there are gaps in the columns of information--essentially the header line looks something like this:
'header1',,,,,'header2','header3'
SmarterCSV gives me this error:
SmarterCSV::DuplicateHeaders (ERROR: duplicate headers: ,,,,,,,,,)
Does anyone know of a way to have SmarterCSV just skip columns without headers and move on? I've tried something akin to the following with no luck:
options = {strip_whitespace: true, key_mapping: {nil => nil}
records = SmarterCSV.process("#{path}#{csv_file}", options)
EDIT:
I've also tried this, and it allows me to complete the processing, but results in an empty array:
options = {
strip_whitespace: true,
key_mapping: {'' => nil},
remove_unmapped_keys: true
}
records = SmarterCSV.process("#{path}#{csv_file}", options)