No commit activity in last 3 years
No release in over 3 years
Updating currency rates made easy.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Runtime

~> 3.0.3
~> 2.1.2
~> 0.4.2
~> 0.7.8
 Project Readme

Currency Updater

The currency updater loads currency rates based on google search.

Description

All rates conversions are based on the Euro (EUR). This version doesn't use a database.

You could interpret the currency updater as a missing part of the standalone money gem.

If you use the money gem, then want to extend the Money::Bank::VariableExchange:

google_currency eu_central_bank

The currency updater itself does one thing: it scrapes currencies.

Installation

Standalone:

gem install currency_updater

With bundler:

gem "currency_updater"

Usage

You have to include the CurrencyUpdater module. Here is a silly example:

class DollarTodayController < ApplicationController
  include CurrencyUpdater
 def index
    @currencies = Updater.new("USD")
  end
end

Fetching Currencies

In order to fetch all currencies defined by ISO 4217 (*):

currencies = Updater.new

or to fetch only one currency:

currencies = Updater.new("USD")

or to fetch some currencies:

currencies = Updater.new(["USD","GBP","RUB"])

Accessing a currency

To access the currency rate, code or name:

currencies.usd.rate # => 1.333
currencies.usd.code # => "USD"
currencies.usd.name # => I18n.t('currency.usd')

Output currencies

You're able to convert the currencies into different formats:

currencies.to_json
currencies.to_yaml
currencies.to_xml

Have a look at the remote specs to get an idea how the output looks like:

ruby remote_spec/remote_spec.rb

Unsupported currencies

Some currency rates are not available today. You could try to update them anyhow.

# lib/currency_updater/currencies.rb
# class Currencies
# EUR is unsupported because it's our reference currency
# TRY is unsupported because it's a method used in actionpack
# the other currencies are not supported because of google

UNSUPPORTED = %w(EUR TRY AFN ALL AMD AOA AZN BAM BIF BMD BSD BTN CDF CUP ETB FIM FKP GEL GNF GYD IMP JEP KGS KMF LRD LSL LYD MGA MMK MNT MRO MZN SBD SHP SOS STD TJS TMM TOP TVD VUV WST ZWD)

Configure the updater

You are able to override the rate_finder behavior for your needs. In case you'd like to find the rates in another way, you can change the rate finder simply like that:

# config/initializers/currency_updater.rb

CurrencyUpdater.setup do |config|
  config.rate_finder = lambda {|currency| 1.2345 }
end

TODOs

  • Maybe it would be a good Idea to provide a currencies.to_exhange_bank method :)

Changelog

  • Fixed a typo in my dependencies (1.0.3)
  • Add all dependencies specified in Gemfile (1.0.2)
  • 2010-11-20: Update Gemspec dependencies (1.0.1)
  • 2010-11-19: Initial commit (1.0.0)

Contributors

  • Jan Riethmayer (@riethmayer, maintainer)

Credits

Thanks to Alex Rabarts for his iso_country_codes.

LICENSE

(The MIT License)

Copyright (c) 2010 urbanvention

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.