Tuesday, 30 October 2007

FasterCSV problem - NoMethodError when trying to call join()

I've been getting this error message:

C:\work\reportscraper\db_uploader>ruby db_uploader.rb --file "Ethos Corporation.xls" > ethos.log

db_uploader.rb:147: undefined method `join' for #<FasterCSV::Row:0x2ea3ab0> (NoMethodError) from c:/ruby/lib/ruby/gems/1.8/gems/fastercsv-1.2.1/lib/faster_csv.rb:65

9:in `each' from c:/ruby/lib/ruby/gems/1.8/gems/fastercsv-1.2.1/lib/faster_csv.rb:65

9:in `each'

from db_uploader.rb:145

It's failing on this line:

data.each { |row|

>>> insert_sql = "INSERT INTO [DATA_UPLOADS] VALUES ( #{row.join(',')});"

puts insert_sql
#db.execute(insert_sql)
}


But I don't understand why this fails but the same method call in
another script is working:

def extract_data_from(filename)

data = FasterCSV.readlines(filename, {:col_sep=>"\t"})

end


cmdoptions = get_commandline_options

data = extract_data_from cmdoptions.single_file

puts
data.size


data.each { |row|
puts row.join(',')
}


==============

Just discovered why. Because in the code with the error, I was passing the :headers option.

data = FasterCSV.readlines(filename, {:col_sep=>"\t", :headers=> true})

In the code that was working, I was only specifying the column separator.

data = FasterCSV.readlines(filename, {:col_sep=>"\t"})

Adding this line

puts row.class

confirms this. The first loop was returning a Row while the second was returning an Array.

Just looked at the documentation and it's actually described in the RDoc:

http://fastercsv.rubyforge.org/fr_method_index.html

"This setting causes FasterCSV.shift() to return rows as FasterCSV::Row objects instead of Arrays and FasterCSV.read() to return FasterCSV::Table objects instead of an Array of Arrays."

Monday, 29 October 2007

Beatles reunion coming soon? W00t!



Noticed this ad while reading my mail today. Made me go "hmm...." a little bit, but hey, if they're selling tickets for it, then it must be true!

NOTE TO SELF: update html and make the image look biiiiger.

Wednesday, 3 October 2007

YouTube viewing session



Interesting what I ended up watching and how I got there. (Most recent is at the top, so go through the list from the bottom.)

It all started with me trying to educate my wife about Rage Against The Machine, and how the Sydney Entertainment Centre would have to be one of the worst places to see them, since no one in their right mind really wants to be seated when watching these guys. "WHAT? You don't know who they are? ZOMG! Watch this then... And feel the funk, y'all!"

I love Daft Punk. I really do. Okay, maybe just the first 2 albums. They became popular around the time these new-fangled things called "electronica" and "big beat" were making the rounds. That faded, and then we all started listening to Post-Rock, then New Rock, then that "angular post-punk proto-new wave sound". God knows what they call it this year. At least hip-hop doesn't suffer from the proliferation of labels like this. There may be strains of hip-hop, but no one ever goes and denies that it is hip-hop. But yeah, you say, all these labels just come from music critics, press releases and assorted musical wankers who blog. Fair enough. You never hear the actual artists themselves putting labels on their music. They just tend to say "rock and roll". Okay... so I've just shot down my assertion about rock music in the second sentence of this paragraph.

Anyway, back to Daft Punk. I just realised last night what an utter fool I was for not getting those tickets to their upcoming appearance here in Sydney. Bugger. Bollocks. Fikifikifiki. Woof woof to the doof doof. Aaaaaargh. I was looking up their live performances on YouTube and they're pretty awesome. Not life changing, but enough to make you dance so hard that you'd fall down. I remember actually dancing to Around The World in front of the stereo over and over again. Of course, only after checking that there was no one home!

I, for one, welcome our new (old) robot overlords.