In: |
csv.rb
|
Parent: | Object |
CSV formatted string/stream reader.
EXAMPLE
read CSV lines until 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
Returns reader instance.
# File csv.rb, line 524 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
# File csv.rb, line 559 def initialize(dev) raise RuntimeError.new('do not instantiate this class directly') end
Parse CSV data and get lines. Given block is called for each parsed row. Block value is always nil. Rows are not cached for performance reason.
# File csv.rb, line 514 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