Class: CNB::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/cnb/base.rb

Direct Known Subclasses

DailyRates, MonthlyRates

Instance Method Summary collapse

Instance Method Details

#rate_for(currency, date) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
# File 'lib/cnb/base.rb', line 7

def rate_for(currency, date)
  fail CurrencyMissing unless currency
  fail DateInFuture    if date > Date.today

  rates_for(date)
  rate = @source.at_css("radek[kod='#{currency}']")

  fail CurrencyNotSupported if rate.nil?

  rate.attr('kurz').tr(',', '.').to_f / rate.attr('mnozstvi').to_f
end