Class: CurrencyExchanger

Inherits:
Object show all
Defined in:
lib/mrpin/core/currency_exchanger/currency_exchanger.rb

Instance Method Summary collapse

Constructor Details

#initializeCurrencyExchanger

Returns a new instance of CurrencyExchanger.



3
4
5
6
7
8
9
10
11
12
# File 'lib/mrpin/core/currency_exchanger/currency_exchanger.rb', line 3

def initialize
  @exchangers = []

  @exchanger_local = ExchangerLocal.new

  @exchangers << ExchangerYahoo0.new
  @exchangers << ExchangerYahoo1.new
  @exchangers << ExchangerFixer.new

end

Instance Method Details

#get_rate(from_currency, to_currency) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/mrpin/core/currency_exchanger/currency_exchanger.rb', line 15

def get_rate(from_currency, to_currency)
  from_currency = from_currency.upcase
  to_currency   = to_currency.upcase

  result = nil

  if from_currency == to_currency
    result = 1.0
  else

    result = @exchanger_local.get_rate(from_currency, to_currency)

    if result.nil?
      result = get_rate_and_cache(from_currency, to_currency)
    end
  end

  if result.nil? || result == 0
    AppInfoBase.instance.on_server_error("can't fetch rate from servers. currency #{from_currency}_#{to_currency}")
    result = 0.0
  end

  result
end