Translate

January 21, 2013

Easy google currency conversion gem

When your app wants to convert local currency to any other currency using current exchange rate, then you can convert it using Google API. like http://www.google.com/ig/calculator?hl=en&q=100USD=?INR. This will give you a json string with the converted value. You need to parse the result and get the converted currency value in your app. You can use USD to Yen, EURO to USD etc .. using Google API.

There is a simple interface to handle this using Google API.
Convert any currency to any other currency using easy to use goog_currency gem
A simple Ruby interface for currency conversion using Google API.

How to use:
Add gem file in Gemfile

gem 'goog_currency'

Use bundle to get this gem installed on your system.
Now in your app code you can use functions like follows:
To Get pounds from usd simply use usd_to_gbp

amount = 223
pounds = GoogCurrency.usd_to_gbp(amount)

Get yen from ponds using gbp_to_jpy

amount = 223
yen = GoogCurrency.gbp_to_jpy(amount)

Similarly ....
pounds = GoogCurrency.jpy_to_gbp(amount)
usd = GoogCurrency.gbp_to_usd(amount) 

etc...

You have to pass the amount to those functions.

This will throw an exception in case of any error.
Throws GoogCurrency::Exception in case of any error. And,
Throws GoogCurrency::NoMethodException if conversion method syntax is invalid.

You can find the Source Code here
And Gem here

goog_currency License
MIT License This software is provided as is, use it your own risk.
Copyright (c)  Girish Sonawane

No comments: