Module | RIO::IF::CSV | lib/rio/if/csv.rb |
Puts a Rio in CSV mode and sets the field and record separators. In csv mode selecting with records will cause each line read to be parsed into a line with the CSV standard library. Specifying using lines to select will return unparsed strings as normal.
# copy a csv file, changing the field separator rio('afile.csv').csv > rio('afile_semicolons.csv').csv(';')
CSV mode also adds two methods columns and skipcolumns which allows selecting columns by column index using Fixnums or Ranges in a way similar to how lines are selected.
# iterate through every line but only get the first three columns rio("afile.csv").csv.columns(0..2) { |array_of_fields| ... } # iterate through every line but skip the columns 2 and 3 through 5 rio("afile.csv").csv.skipcolumns(2,3..5) { |array_of_fields| ... } # an array containg all but the first line returning columns 5,6 and 7 rio("afile.csv").csv.columns(5..7).skiplines[0]
See RIO::Doc::INTRO for complete documentation on csv mode.
Copyright © 2005,2006,2007 Christopher Kleckner. All rights reserved.