Class: CNBRates
- Inherits:
-
Object
- Object
- CNBRates
- 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
-
#currency_list ⇒ Object
readonly
Returns the value of attribute currency_list.
Instance Method Summary collapse
-
#initialize(options = {}) ⇒ CNBRates
constructor
A new instance of CNBRates.
- #rate(currency, amount = 1) ⇒ Object
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( = {}) @date = [:date] || Date.today @filename = [:filename] || '' @big_decimals = [:big_decimals] || false @date = @date.strftime('%d.%m.%Y') @currency_list = [] parse_list end |
Instance Attribute Details
#currency_list ⇒ Object (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 |