class Object
Constants
- FCSV
This class provides a complete interface to CSV files and data. It offers tools to enable you to read and write to and from Strings or IO objects, as needed.
Reading¶ ↑
From a File¶ ↑
A Line at a Time¶ ↑
FasterCSV.foreach("path/to/file.csv") do |row| # use row here... end
All at Once¶ ↑
arr_of_arrs = FasterCSV.read("path/to/file.csv")
From a
String
¶ ↑A Line at a Time¶ ↑
FasterCSV.parse("CSV,data,String") do |row| # use row here... end
All at Once¶ ↑
arr_of_arrs = FasterCSV.parse("CSV,data,String")
Writing¶ ↑
To a File¶ ↑
FasterCSV.open("path/to/file.csv", "w") do |csv| csv << ["row", "of", "CSV", "data"] csv << ["another", "row"] # ... end
To a
String
¶ ↑csv_string = FasterCSV.generate do |csv| csv << ["row", "of", "CSV", "data"] csv << ["another", "row"] # ... end
Convert a Single Line¶ ↑
csv_string = ["CSV", "data"].to_csv # to CSV csv_array = "CSV,String".parse_csv # from CSV
Shortcut Interface¶ ↑
FCSV { |csv_out| csv_out << %w{my data here} } # to $stdout FCSV(csv = "") { |csv_str| csv_str << %w{my data here} } # to a String FCSV($stderr) { |csv_err| csv_err << %w{my data here} } # to $stderr FCSV($stdin) { |csv_in| csv_in.each { |row| p row } } # from $stdin
Advanced Usage¶ ↑
Wrap an IO
Object
¶ ↑csv = FCSV.new(io, options) # ... read (with gets() or each()) from and write (with <<) to csv here ...
Public Instance Methods
FCSV(*args, &block)
click to toggle source
Another name for FCSV::instance()
.
# File lib/faster_csv.rb, line 2009 def FCSV(*args, &block) FCSV.instance(*args, &block) end
FasterCSV(*args, &block)
click to toggle source
Another name for FasterCSV::instance()
.
# File lib/faster_csv.rb, line 2004 def FasterCSV(*args, &block) FasterCSV.instance(*args, &block) end