Feature #10316
closed
Added by tramuntanal (Oliver Valls) over 9 years ago.
Updated about 6 years ago.
Description
I've been looking for a CSV.foreach equivalent which either
- ignores malformed CSV rows
- or returns a nil row or a row with a parsed success flag.
Can I collaborate to develop this functionallity? Symply sending a patch here?
- Assignee deleted (
nobu (Nobuyoshi Nakada))
- Target version deleted (
2.2.0)
- Status changed from Open to Assigned
- Assignee set to kou (Kouhei Sutou)
- Status changed from Assigned to Rejected
You can implement it with the following code:
CSV.open(path) do |csv|
loop do
begin
row = csv.shift
rescue ArgumentError # For old csv library
# ignore
rescue CSV::MalformedCSVError # For the latest csv library (not released yet)
# ignore
else
# Do what you want with "row"
end
end
end
See also: https://github.com/ruby/csv/issues/25
Also available in: Atom
PDF
Like0
Like0Like0Like0Like0