James Gray
3/7/2007 4:20:00 PM
On Mar 7, 2007, at 10:09 AM, Samantha wrote:
> James Edward Gray II wrote:
>>> If someone could point me in the right direction, of possible
>>> libraries that would help or the such, I'd love to go read there
>>> and study on it and try to figure it out. Not asking for
>>> answers, just asking for resources. :)
>>
>> The standard CSV library will do the parsing for you, but this
>> case looks very simple so you probably don't need it. However, if
>> the first row of the file has the field names, it might be worth
>> looking at FasterCSV which will build the Hashes for you:
> Thanks! The first row does not have field names, however, I'm sure
> I could add them.
Actually, FasterCSV plans for that too. I should have said that.
Here's a taste:
>> require "rubygems"
=> false
>> require "faster_csv"
=> true
>> csv = <<END_CSV
Book|Programming|Good Stuff.
Book|Home Improvement|Sounds like work.
END_CSV
=> "Book|Programming|Good Stuff.\nBook|Home Improvement|Sounds like
work.\n"
>> FCSV.parse(csv, :col_sep => "|", :headers => [:cat, :sub, :des])
do |row|
?> p row.to_hash
>> end
{:sub=>"Programming", :cat=>"Book", :des=>"Good Stuff."}
{:sub=>"Home Improvement", :cat=>"Book", :des=>"Sounds like work."}
=> nil
Hope that helps.
James Edward Gray II