# # A simple ruby script to convert currency # can be edited to check stocks, highs, lows, etc. # # Written by: Steve at r3lax.com # # Usage: money.rb <amount><from-code><to-code> # Where: <from-code>,<to_code> -- ISO Currency codes # # MUST BE CONNECTED TO THE INTERNET # Must have ruby-finance installed require 'finance/currency' #Take arguments in from command line c = ARGV #Ensure that usage is proper valid = /^([\+-]?\d*(?:\.\d*)?)(\S+)\s(\S+)/ if exchange = valid.match(c) amount = exchange[1] from_code = exchange[2] to_code = exchange[3] #Let Finance::Currency do its magic puts Finance::Currency::convert(to_code.to_s, from_code.to_s, amount) else #if usage is invalid - inform the user puts '-----USAGE IS-----' puts '<amount><from-code> <to-code>' puts '<from-code>,<to-code> -- ISO Currency codes' end