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

January 17, 2013

How to installing gems when no network

If you have a system with no network connection or you have very restricted firewall connection then its very difficult to install gems.Here is simple work around to solve such problem. You at least need a way to move the files on system.
  • Step 1: Install the required gem on internet connected computer. You can disable the document generation if you desire.
    $ gem install gem_name -i dir_name --no-rdoc --no-ri
    

  • Step 2:  RubyGems has downloaded all the .gem files and placed them in dir_name/cache. You need to Copy this directory to a USB pen drive or some thing else to move directory to the target system. you can use a secure network to transfer it.
  • $ cp -r dir_name/cache /path_to/usb_pen_drive/gems
    

  • Step 3: Install the gems on the target system from the local files
  • $ cd /path_to/usb_pen_drive/gems
    $ gem install --force --local *.gem
    
Thats it ... Your system has a required gem installed