-
-
Save ylluminate/9cbc8f04053f79247ed2a7db5d4a020d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
require 'net/http' | |
def convert_currency(from_curr, to_curr) | |
doc = Net::HTTP.get('www.google.com', "/finance/converter?a=1&from=#{from_curr}&to=#{to_curr}") | |
regexp = Regexp.new("(\\d+\\.{0,1}\\d*)\\s+#{to_curr}") | |
regexp.match doc | |
$1.to_f | |
end | |
puts "1 USD = #{convert_currency('USD', 'EUR')} EUR" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment