Do not raise Encoding::UndefinedConversionError during CSV rendering

Use replacement characters instead of exceptions.
This commit is contained in:
Patrick Gansterer 2018-12-11 15:27:32 +01:00
parent a4f5b8fb33
commit d67bbe447f
1 changed files with 3 additions and 2 deletions

View File

@ -13,13 +13,14 @@ class RenderCSV
end
def to_csv
options = @options.select {|k| %w(col_sep row_sep encoding).include? k.to_s}
CSV.generate options do |csv|
options = @options.select {|k| %w(col_sep row_sep).include? k.to_s}
ret = CSV.generate options do |csv|
if h = header
csv << h
end
data {|d| csv << d}
end
ret.encode(@options[:encoding], invalid: :replace, undef: :replace)
end
def header