Class: ActiveCurrency::Rate

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
app/models/active_currency/rate.rb

Class Method Summary collapse

Class Method Details

.value_for(from, to, date = nil) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
# File 'app/models/active_currency/rate.rb', line 13

def self.value_for(from, to, date = nil)
  from = Money::Currency.new(from)
  to = Money::Currency.new(to)
  return 1 if from == to

  scope = date ? before(date) : all
  scope
    .where(from: from.iso_code, to: to.iso_code)
    .order(:created_at)
    .last
    &.value
end