FasterCSV 1.0.0 Released
···
========================
Ara strikes again, adding his second awesome enhancement to FasterCSV. Here's some example code showing off FasterCSV::Table:
#!/usr/local/bin/ruby -w
# csv_table.rb
#
# Created by James Edward Gray II on 2006-11-04.
# Copyright 2006 Gray Productions. All rights reserved.
#
# Feature implementation and example code by Ara.T.Howard.
require "faster_csv"
table = FCSV.parse(DATA, :headers => true, :header_converters => :symbol)
# row access
table[0].class # => FasterCSV::Row
table[0].fields # => ["zaphod", "beeblebrox", "42"]
# column access
table[:first_name] # => ["zaphod", "ara"]
# cell access
table[1][0] # => "ara"
table[1][:first_name] # => "ara"
table[:first_name][1] # => "ara"
# manipulation
table << %w[james gray 30]
table[-1].fields # => ["james", "gray", "30"]
table[:type] = "name"
table[:type] # => ["name", "name", "name"]
table[:ssn] = %w[123-456-7890 098-765-4321]
table[:ssn] # => ["123-456-7890", "098-765-4321", nil]
# iteration
table.each do |row|
# ...
end
table.by_col!
table.each do |col_name, col_values|
# ...
end
# output
puts table
# >> first_name,last_name,age,type,ssn
# >> zaphod,beeblebrox,42,name,123-456-7890
# >> ara,howard,34,name,098-765-4321
# >> james,gray,30,name,
__END__
first_name,last_name,age
zaphod,beeblebrox,42
ara,howard,34
Thank you Ara!
What is FasterCSV?
------------------
(from the README)
FasterCSV is intended as a replacement to Ruby's standard CSV library.
It was designed to address concerns users of that library had and it has
three primary goals:
1. Be significantly faster than CSV while remaining a pure Ruby library.
2. Use a smaller and easier to maintain code base. (FasterCSV is larger now,
but considerably richer in features. The parsing core remains quite small.)
3. Improve on the CSV interface.
What's New?
-----------
(highlights from the CHANGELOG)
* The slurping methods now return the new FasterCSV::Table objects.
* Fixed parser so multibyte :col_sep works now.
* Fixed FasterCSV.rewind() to reset the FasterCSV.lineno() counter.
* Fixed FasterCSV.rewind() to reset the header processing.
* Enhanced FasterCSV::Row.fields() to support Ranges, even for headers.
* Added a few examples for usage.
Migrating from CSV to FasterCSV?
--------------------------------
The README includes a section on the differences and you can read that
here:
http://fastercsv.rubyforge.org/
You call also see general usage in the documentation of the interface,
right here:
http://fastercsv.rubyforge.org/classes/FasterCSV.html
For quick and dirty switching, try:
begin
require "faster_csv"
FasterCSV.build_csv_interface
rescue LoadError
require "csv"
end
# ... use CSV here ...
If FasterCSV isn't meeting your needs, I want to here about it:
Where can I learn more?
-----------------------
FasterCSV is hosted on RubyForge.
Project page: http://rubyforge.org/projects/fastercsv/
Documentation: http://fastercsv.rubyforge.org/
Downloads: http://rubyforge.org/frs/?group_id=1102
How do I get FasterCSV?
-----------------------
FasterCSV is a gem, so as long as you have RubyGems installed it's as
simple as:
$ sudo gem install fastercsv
If you need to install RubyGems, you can download it from:
http://rubyforge.org/frs/?group_id=126&release_id=5803
FasterCSV can also be installed manually. Just download the latest
release and follow the instructions in INSTALL:
http://rubyforge.org/frs/?group_id=1102&release_id=7740
James Edward Gray II