Skip to content

Instantly share code, notes, and snippets.

@RoxasShadow
Created October 6, 2013 14:20
Show Gist options
  • Select an option

  • Save RoxasShadow/6854683 to your computer and use it in GitHub Desktop.

Select an option

Save RoxasShadow/6854683 to your computer and use it in GitHub Desktop.
require 'money'
require 'json'
require 'open-uri'
if ARGV.length == 3
from = ARGV[0]
to = ARGV[1]
money = ARGV[2].to_f
else
from = 'JPY'
to = 'EUR'
money = ARGV[0].to_f
end
rate = JSON.parse(open("http://rate-exchange.appspot.com/currency?from=#{from}&to=#{to}&q=1").read)['rate'].to_f
Money.add_rate from, to, rate
puts "#{Money.new(money, from).exchange_to(to)} (rate: #{rate.round(4)})"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment