Class: Gera::RateSource

Inherits:
ApplicationRecord show all
Extended by:
CurrencyPairGenerator
Includes:
Authority::Abilities
Defined in:
app/models/gera/rate_source.rb

Constant Summary collapse

RateNotFound =
Class.new StandardError

Class Method Summary collapse

Instance Method Summary collapse

Methods included from CurrencyPairGenerator

generate_pairs_from_currencies

Class Method Details

.available_pairsObject



36
37
38
# File 'app/models/gera/rate_source.rb', line 36

def self.available_pairs
  generate_pairs_from_currencies supported_currencies
end

.get!Object



40
41
42
# File 'app/models/gera/rate_source.rb', line 40

def self.get!
  where(type: name).take!
end

.supported_currenciesObject



32
33
34
# File 'app/models/gera/rate_source.rb', line 32

def self.supported_currencies
  raise 'not implemented'
end

Instance Method Details

#actual_ratesObject



56
57
58
# File 'app/models/gera/rate_source.rb', line 56

def actual_rates
  external_rates.where(snapshot_id: actual_snapshot_id)
end

#find_rate_by_currency_pair(pair) ⇒ Object



48
49
50
# File 'app/models/gera/rate_source.rb', line 48

def find_rate_by_currency_pair(pair)
  actual_rates.find_by_currency_pair pair
end

#find_rate_by_currency_pair!(pair) ⇒ Object



44
45
46
# File 'app/models/gera/rate_source.rb', line 44

def find_rate_by_currency_pair!(pair)
  find_rate_by_currency_pair(pair) || raise(RateNotFound, pair)
end

#is_currency_supported?(cur) ⇒ Boolean

Returns:

  • (Boolean)


64
65
66
67
# File 'app/models/gera/rate_source.rb', line 64

def is_currency_supported?(cur)
  cur = Money::Currency.find cur unless cur.is_a? Money::Currency
  supported_currencies.include? cur
end

#to_sObject



52
53
54
# File 'app/models/gera/rate_source.rb', line 52

def to_s
  name
end