gapfish / daily_exchange_rates_bank

A bank for the money gem that determines exchange rates for any desired date.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

DailyExchangeRatesBank

Codeship Status for gapfish/daily_exchange_rates_bank

A bank for the money gem that determines exchange rates for any desired date. Missing exchange rates are fetched from api.frankfurter.app. This is configurable with the RATES_API_URL environment variable.

Installation

Add this line to your application's Gemfile:

gem 'daily_exchange_rates_bank'

and then execute:

$ bundle

Or install it yourself:

$ gem install daily_exchange_rates_bank

Usage

require 'daily_exchange_rates_bank'

bank = DailyExchangeRatesBank.new
Money.default_bank = bank

Money.new(100, 'EUR').exchange_to('USD')  # => Money.new(109, 'USD')
bank.get_rate('EUR', 'USD') # => 1.0935

date = Date.new(2019, 7, 1)
bank.exchange(100, 'EUR', 'USD', date) # => Money.new(113, 'USD')
bank.exchange_with(Money.new(100, 'EUR'), 'USD', date) # => Money.new(113, 'USD')

If you are using the money-rails gem, you can set the default_bank in config/initializers/money.rb:

MoneyRails.configure do |config|
  config.default_bank = DailyExchangeRatesBank.new

  # remaining config
end

About

A bank for the money gem that determines exchange rates for any desired date.

License:GNU General Public License v3.0


Languages

Language:Ruby 100.0%