In: |
csv.rb
|
Parent: | Object |
DESCRIPTION
CSV::Reader -- CSV formatted string/stream reader.
EXAMPLE
Read CSV lines untill the first column is 'stop'. CSV::Reader.parse(File.open('bigdata', 'rb')) do |row| p row break if !row[0].is_null && row[0].data == 'stop' end
SYNOPSIS
reader = CSV::Reader.create(str_or_readable)
ARGS
str_or_readable: a CSV data to be parsed. A String or an IO.
RETURNS
reader: Created instance.
DESCRIPTION
Create instance. To get parse result, see CSV::Reader#each.
# File csv.rb, line 278 def Reader.create(str_or_readable, col_sep = ?,, row_sep = nil) case str_or_readable when IO IOReader.new(str_or_readable, col_sep, row_sep) when String StringReader.new(str_or_readable, col_sep, row_sep) else IOReader.new(str_or_readable, col_sep, row_sep) end end
SYNOPSIS
CSV::Reader.parse(str_or_readable) do |row| ... end
ARGS
str_or_readable: a CSV data to be parsed. A String or an IO. row: a CSV::Row; an Array of a CSV::Cell in a line.
RETURNS
nil
DESCRIPTION
Parse CSV data and get lines. Caller block is called for each line with an argument which is a chunk of cells in a row. Block value is always nil. Rows are not cached for performance reason.
# File csv.rb, line 308 def Reader.parse(str_or_readable, col_sep = ?,, row_sep = nil) reader = create(str_or_readable, col_sep, row_sep) reader.each do |row| yield(row) end reader.close nil end
# File csv.rb, line 376 def initialize(dev) raise RuntimeError.new('Do not instanciate this class directly.') end
SYNOPSIS
CSV::Reader#each do |row| ... end
ARGS
row: a CSV::Row; an Array of a CSV::Cell in a line.
RETURNS
nil
DESCRIPTION
Caller block is called for each line with an argument which is a chunk of cells in a row. Block value is always nil. Rows are not cached for performance reason.
# File csv.rb, line 335 def each while true row = Row.new parsed_cells = get_row(row) if parsed_cells == 0 break end yield(row) end nil end