Skip to content

Instantly share code, notes, and snippets.

@martonpe
Forked from ylluminate/convert_currency.rb
Last active June 10, 2021 07:32
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save martonpe/1c797ef3332e9724a76a to your computer and use it in GitHub Desktop.
Save martonpe/1c797ef3332e9724a76a to your computer and use it in GitHub Desktop.
#!/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"
@huykon
Copy link

huykon commented Jun 23, 2018

not working now

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment