Thursday, March 20, 2008

First Cut of Ruby

I wrote my first Ruby app yesterday. I've been meaning to do this for years but I finally did it....I was stuck at 87% for quite a while there.
Anyway, I like learning new things and like most people I find that if I use it to write an application that I am interested in, it makes learning a lot easier, more fun, and I think I learn more.
So here is an overview of my application and some things that I learned along the way. If anyone is interested in the code, leave a comment and I'll send or post it.

MLB Stat Scraper
The application basically grabs stats from a website and puts it into a text file. The reason that I wanted this was so that I would be able to look up preseason stats without having to be online. I could just print it out and take it with me. I would also not have to go to 30 team pages and cut and paste them all manually (it takes longer than you think).
I ended up using a Ruby HTML parser library called Hpricot to help me find the text that I was looking for. It worked really well once I figured out how to use RubyGems to install it. In retrospect, I didn't need Hpricot since the stats that I was looking for was placed between pre tags and was marked in such a way that I think I could have got the text with the standard Ruby libraries.
I also used JRuby instead of Ruby and that seemed to work fine as well. There were some snags when I was installing RubyGems and Hpricot for JRuby, but it all eventually worked.
I'll get into the reasons for JRuby in a later post.

Ruby Impressions
I'm liking Ruby. I need to understand how things work a whole lot better, but it did what I wanted with very minimal code. The bulk of the code was less than 20 lines and after getting everything installed it took maybe an hour or so of total time to write.

1 comment:

aaron said...

cool, i used the Hpricot gem too. looking forward to the JRuby reasoning.