1

As stated in this documentation I can change the standard col_sep e.g. from "," to ";".

How can I alter this to use both "," and ";" as a col_sep.

My actual code:

def process!
  @imported_count = 0
  CSV.foreach(file.path, headers: true, header_converters: :symbol, col_sep: ",") do |row|
    order = Order.assign_from_row(row)
    if order.save
      @imported_count += 1
    else
      errors.add :base, "Line #{$.} - #{order.errors.full_messages.join(",")}"
    end
  end
end

Thanks in Advance!

Pardeep Dhingra
  • 3,916
  • 7
  • 30
  • 56
CottonEyeJoe
  • 720
  • 1
  • 7
  • 28

1 Answers1

1

col_sep only accepts one value. You can see examples of how it's used here:

http://rxr.whitequark.org/mri/source/lib/csv.rb (lines 1654 and 1803 are a couple examples)

One workaround could be replacing all instances of one separator value with another by using something like gsub. Not the silver bullet you were hoping for, but depending on your requirements it could do the trick!

vthomas2007
  • 153
  • 6