Do not raise Encoding::UndefinedConversionError during CSV rendering
Use replacement characters instead of exceptions.
This commit is contained in:
parent
a4f5b8fb33
commit
d67bbe447f
1 changed files with 3 additions and 2 deletions
|
@ -13,13 +13,14 @@ class RenderCSV
|
||||||
end
|
end
|
||||||
|
|
||||||
def to_csv
|
def to_csv
|
||||||
options = @options.select {|k| %w(col_sep row_sep encoding).include? k.to_s}
|
options = @options.select {|k| %w(col_sep row_sep).include? k.to_s}
|
||||||
CSV.generate options do |csv|
|
ret = CSV.generate options do |csv|
|
||||||
if h = header
|
if h = header
|
||||||
csv << h
|
csv << h
|
||||||
end
|
end
|
||||||
data {|d| csv << d}
|
data {|d| csv << d}
|
||||||
end
|
end
|
||||||
|
ret.encode(@options[:encoding], invalid: :replace, undef: :replace)
|
||||||
end
|
end
|
||||||
|
|
||||||
def header
|
def header
|
||||||
|
|
Loading…
Add table
Reference in a new issue