class CSV2::Parser
- CSV2::Parser
- Reference
- Object
Overview
A CSV parser. It lets you consume a CSV row by row.
Most of the time CSV#parse
and CSV#each_row
are more convenient.
Defined in:
csv/parser.crConstructors
-
.new(string_or_io : String | IO, separator : Char = DEFAULT_SEPARATOR, quote_char : Char = DEFAULT_QUOTE_CHAR)
Creates a parser from a
String
orIO
.
Instance Method Summary
-
#each_row(&) : Nil
Yields each of the remaining rows as an
Array(String)
. -
#each_row
Returns an
Iterator
ofArray(String)
for the remaining rows. -
#next_row(array : Array(String)) : Array(String) | Nil
Reads the next row into the given array.
-
#next_row : Array(String) | Nil
Returns the next row in the CSV, if any, or
nil
. -
#parse : Array(Array(String))
Returns the remaining rows.
-
#rewind
Rewinds this parser to the first row.
Constructor Detail
def self.new(string_or_io : String | IO, separator : Char = DEFAULT_SEPARATOR, quote_char : Char = DEFAULT_QUOTE_CHAR)
#
Creates a parser from a String
or IO
.
Optionally takes the optional separator and quote_char arguments for
specifying non-standard cell separators and quote characters
Instance Method Detail
def next_row(array : Array(String)) : Array(String) | Nil
#
Reads the next row into the given array.
Returns that same array, if a row was found, or nil
.