Sha256: 606d4138c3bbe5a5cf24c8c339620f37aa6fbf90bea2e1f5ff3318dd4d97700c

Contents?: true

Size: 1.91 KB

Versions: 1

Compression:

Stored size: 1.91 KB

Contents

# Money Historical Bank
[![Build Status](https://secure.travis-ci.org/coutud/money-historical-bank.png)](http://travis-ci.org/coutud/money-historical-bank)

A gem that add a `Money::Bank` able to handle historical rates, and infer rates from limited rates.

* You can add rates for any currency pair, at a special date. Use `home_run` gem if you need fast date handling in ruby.
* If no rates exist for a given date, the gem will try to download historical rates from [open-exchange-rates](http://josscrowcroft.github.com/open-exchange-rates/)
* The gem is able to guess inverse rates (EURUSD rate when only USDEUR is present), and go through USD when using other pairs. For example, GBPEUR will be calculated using USDGBP and USDEUR. This strategy isn't used if said rate (GBPEUR) is already set.
* No caching exists, but you can use `import_data` and `export_data` the same way `Money::Bank::VariableExchange` works.

## Usage

```ruby
require 'money/bank/historical_bank'
mh = Money::Bank::HistoricalBank.new

# Exchanges 1000 EUR to USD using Date.today (default if no date has been entered).
# Will download today's rates if none have been entered
mh.exchange_with(1000.to_money('EUR'), 'USD')

# Exchanges 1000 EUR to USD using historical rates
date = Date.new(2009,9,9)
mh.set_rate(date, 'USD', 'EUR', 0.7634)
mh.exchange_with(date, 1000.to_money('USD'), 'EUR') # => 763.4 EUR

Money.default_bank = mh
```

## Refs
Created using mainly the base `VariableExchange` implementation, OpenExchangeRates implementation and idea based on `money-open-exchange-rates` gem.

* https://github.com/currencybot/open-exchange-rates
* https://github.com/RubyMoney/money
* https://github.com/spk/money-open-exchange-rates

## Extension

Feel free to create a new loader (cf `OpenExchangeRatesLoader`) if you know a source for more historical data.
Feel free to suggest refactoring.

## License
The MIT License

Copyright © 2011 Damien Couture <wam@atwam.com>

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
money-historical-bank-0.0.2 README.markdown