Skip to content

Latest commit

 

History

History
55 lines (40 loc) · 924 Bytes

README.md

File metadata and controls

55 lines (40 loc) · 924 Bytes

csv_parser

Parse CSV with multiline fields and escaped double quotes.

Installation

Add this line to your application's Gemfile:

gem 'csv_parser'

And then execute:

$ bundle

Or install it yourself as:

$ gem install csv_parser

Usage

csv with multiline fields

aa
bb
cc dd
ee    
require 'csv_parser'

parser = CsvParser::Parser.new
csv = "\"aa\nbb\",cc,dd\nee"
result = parser.parse(csv)
p result.length #=> 2
p result[0] #=> ["aa\nbb", "cc", "dd"]
p result[1] #=> ["ee"]

csv with escaped double quotes

aa bb cc dd
ff gg hh  
ii,jj kk    
require 'csv_parser'

parser = CsvParser::Parser.new
csv = "aa,bb,cc,dd\nff,gg,hh\n\"ii,jj\",kk"
result = parser.parse(csv)
p result.length #=> 3
p result[0] #=> ["aa", "bb", "cc", "dd"]
p result[1] #=> ["ff", "gg", "hh"]
p result[2] #=> ["ii,jj", "kk"]