Class: CNBRates

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

Constant Summary collapse

SOURCE_URL =
'http://www.cnb.cz/cs/financni_trhy/devizovy_trh/kurzy_devizoveho_trhu/denni_kurz.txt?date='

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ CNBRates

Returns a new instance of CNBRates.



14
15
16
17
18
19
20
21
22
# File 'lib/cnb_rates.rb', line 14

def initialize(options = {})
  @date = options[:date] || Date.today
  @filename = options[:filename] || ''
  @big_decimals = options[:big_decimals] || false
  @date = @date.strftime('%d.%m.%Y')
  @currency_list = []

  parse_list
end

Instance Attribute Details

#currency_listObject (readonly)

Returns the value of attribute currency_list.



12
13
14
# File 'lib/cnb_rates.rb', line 12

def currency_list
  @currency_list
end

Instance Method Details

#rate(currency, amount = 1) ⇒ Object



24
25
26
27
28
29
30
31
32
# File 'lib/cnb_rates.rb', line 24

def rate(currency, amount=1)
  method_name = currency.downcase.to_sym
  rate = if respond_to?(method_name) then
           send(method_name)
         else
           @big_decimals ? BigDecimal.new(1) : 1.0
         end
  rate * amount
end