class Arbolito::Currency::Rate

Attributes

price[R]
quote[R]
rated_at[R]

Public Class Methods

new(price, from_to_hash, rated_at = Time.now) click to toggle source
# File lib/arbolito/currency/rate.rb, line 6
def initialize(price, from_to_hash, rated_at = Time.now)
  @quote = Quote.new(from_to_hash)
  @price = BigDecimal.new(price)
  @rated_at = rated_at
end

Public Instance Methods

==(other_currency_rate) click to toggle source
# File lib/arbolito/currency/rate.rb, line 24
def ==(other_currency_rate)
  raise TypeError unless other_currency_rate.is_a?(CurrencyRate)

  @quote == other_currency_rate.quote && @price == @other.price
end
backwards() click to toggle source
# File lib/arbolito/currency/rate.rb, line 16
def backwards
  self.class.new(BigDecimal.new(1) / @price, @quote.backwards.to_hash)
end
convert(money) click to toggle source
# File lib/arbolito/currency/rate.rb, line 12
def convert(money)
  @price * BigDecimal.new(money)
end
expired?(expiration_time) click to toggle source
# File lib/arbolito/currency/rate.rb, line 20
def expired?(expiration_time)
  (Time.now - rated_at) > expiration_time
end