Lesson content is currently in draft form.
The CSV (or FasterCSV) library
(draft)
If you have Ruby 1.8, install the FasterCSV gem.
If you have Ruby 1.9, FasterCSV is part of the CSV library, so you just need to have the require
statement.
In our my_code.rb
file, I’ve handled both conditions like so:
1 2 3 4 5 |
|
CSV Files
(draft)
The Sunlight Foundation maintains a spreadsheet of Congressmember data, including social media usernames.
Download our mirroed copy for this tutorial here: http://nottwitter.danwin.com/sunlight-foundation-congress-master.csv
It is also in your working-directory
Parsing CSV
We could parse with the string split
method, but even a simple CSV file can have many ugly variations and irregularities.
Use the CSV library instead:
1 2 3 4 5 6 7 |
|
The headers option
1
|
|
Each data row is represented as a hash, with the column names conveniently used as keys.
Convenience method for congressmembers
In our my_code.rb
1 2 3 4 5 6 7 8 9 10 11 12 13 |
|