Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Use Google calculator to convert currency in Ruby
require 'faraday'
require 'faraday_middleware'
require 'json'
# Debug:
# require "pry"
country_code_src = "USD"
country_code_dst = "INR"
connection = Faraday.get("{country_code_src}=?#{country_code_dst}")
currency_comparison_hash = eval connection.body #Google's output is not JSON, it's a hash
dst_currency_value, *dst_currency_text = *currency_comparison_hash[:rhs].split(' ')
dst_currency_value = dst_currency_value.to_f
dst_currency_text = dst_currency_text.join(' ')
puts "#{country_code_dst} -> #{dst_currency_value} (#{dst_currency_text} to 1 #{country_code_src})"

This comment has been minimized.

Copy link

martonpe commented Apr 8, 2015

Found this Gist somewhere on SO, so I thought I'd drop a line that iGoogle has been since decommissioned. You can find a working example with Google's finance calculator here

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.