The problem is in CSV#encode_re
: the parameter row_sep: "|[]\n"
is converted to a Regexp.
What can redefine this method:
class CSV
def encode_re(*chunks)
encode_str(*chunks)
end
end
CSV.open('output.txt', 'w', col_sep: '|', row_sep: "|[]\n"
) do |csv|
csv << [1,2,3]
csv << [4,5,6]
end
The result is:
1|2|3|[]
4|5|6|[]
I found no side effect, but I don't feel comfortble to redefine CSV, so I would recommend to create a new CSV-variant:
#Class to create LEDES98
class LEDES_CSV < CSV
def encode_re(*chunks)
encode_str(*chunks)
end
end
LEDES_CSV.open('output.txt', 'w', col_sep: '|', row_sep: "|[]\n"
) do |csv|
csv << [1,2,3]
csv << [4,5,6]
end
Then you can use the 'original' CSV and for LEDES-files you can use the LEDES_CSV.