| Class | CSV::Reader |
| In: |
csv.rb
|
| Parent: | Object |
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
Returns reader instance.
# File csv.rb, line 542 def Reader.create(str_or_readable, fs = ',', rs = nil) case str_or_readable when IO IOReader.new(str_or_readable, fs, rs) when String StringReader.new(str_or_readable, fs, rs) else IOReader.new(str_or_readable, fs, rs) end end
# File csv.rb, line 577 def initialize(dev) raise RuntimeError.new('Do not instanciate 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 528 def Reader.parse(str_or_readable, fs = ',', rs = nil, &block) reader = Reader.create(str_or_readable, fs, rs) if block reader.each do |row| yield(row) end reader.close nil else reader end end
ruby-doc.org is a community service provided by James Britt and Happy Camper Studios, a Phoenix, Arizona, Ruby application development company.
Documentation content on ruby-doc.org is provided by remarkable members of the Ruby community.
For more information on the Ruby programming language, visit ruby-lang.org.
Want to help improve Ruby's API docs? See Ruby Documentation Guidelines.