Showing posts with label gem. Show all posts
Showing posts with label gem. Show all posts

Sunday, March 8, 2009

scottbarr-number_to_text RubyGem

I was playing around with a bit of Ruby to convert numbers to text a few weeks ago but never finished it and forgot all about it. Today Guest11057 (thats an extremely boring nick!) on the #rubyonrails IRC channel asked if something like this existed, and apparently it doesn't. That reminded me about the mothballed code, and motivated me to finish it off and package it up as a RubyGem. To convert a number to text:
n = Number.new(119)
puts n.to_text # => "one-hundred-and-nineteen"
I'm not happy with how the implementation came, but it does the job. I'll clean it up to work a bit nicer sometime :) If you need to convert numbers to text in Ruby, take a look at http://github.com/scottbarr/number_to_text/tree/master

Sunday, February 15, 2009

YahooCurrency Gem

I recently created the YahooCurrency Ruby gem that gets currency exchange rates from Yahoo! Finance. Originally the code was part of a working Ruby on Rails demo I created about 12 months ago. A project we are currently working on needed exchange rates, so i created a Gem from the original code so we could easily reuse it across any of our future Ruby projects. We discussed making the project open source, and agreed that it would probably be useful for others, and also great for Global IT Creations to contribute something back to the open source. It is only a small contribution, but you have to start somewhere. Here is some example code...
exchange_rate = YahooCurrency.get_rate!("JPY", "USD")
exchange_rate.from #=> "JPY"
exchange_rate.to #=> "USD"
exchange_rate.rate #=> 0.0111
exchange_rate.timestamp #=> Wed Feb 11 22:20:00 +0800 2009
Get the source or the gem from http://github.com/scottbarr/yahoo_currency/tree/master Hopefully this will be the first of many projects that GITC releases as Open Source.