Sha256: 9c1d764735070102fbd77dbe600d1061c4dc2d6fc7a96c30d607da07edacdb68
Contents?: true
Size: 1.22 KB
Versions: 3
Compression:
Stored size: 1.22 KB
Contents
# Example using BNA (Banco NaciĆ³n de Argentina) and storing rates daily in ActiveRecord. require 'danconia/integrations/active_record' require 'danconia/exchanges/bna' ActiveRecord::Base.logger = Logger.new(STDOUT) ActiveRecord::Base.establish_connection adapter: 'sqlite3', database: ':memory:' ActiveRecord::Schema.define do # You can use this in a Rails migration create_table :exchange_rates do |t| t.date :date t.string :pair, limit: 6 t.string :rate_type t.decimal :rate, precision: 12, scale: 6 t.index [:date, :pair, :rate_type], unique: true end end Danconia.configure do |config| config.default_exchange = Danconia::Exchanges::BNA.new( store: Danconia::Stores::ActiveRecord.new(unique_keys: %i[date pair rate_type], date_field: :date) ) end # Periodically call this method to keep the rates up to date puts 'Updating rates...' Danconia.config.default_exchange.update_rates! # Uses the latest rate puts Money(1, 'USD').exchange_to('ARS', rate_type: 'billetes').inspect puts Money(1, 'USD').exchange_to('ARS', rate_type: 'divisas').inspect # Raises Danconia::Errors::ExchangeRateNotFound as there is no rate for that date # Money(1, 'USD').exchange_to('ARS', rate_type: 'billetes', date: Date.new(2000))
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
danconia-0.4.0 | examples/bna.rb |
danconia-0.3.1 | examples/bna.rb |
danconia-0.3.0 | examples/bna.rb |