Class: Core
- Inherits:
-
Object
- Object
- Core
- Defined in:
- lib/fafx/core.rb
Instance Attribute Summary collapse
-
#currencies ⇒ Object
readonly
Returns the value of attribute currencies.
-
#dates ⇒ Object
readonly
Returns the value of attribute dates.
-
#rates ⇒ Object
readonly
Returns the value of attribute rates.
Instance Method Summary collapse
-
#initialize ⇒ Core
constructor
A new instance of Core.
- #rate(curr) ⇒ Object
- #rates_at(date, curr) ⇒ Object
Constructor Details
#initialize ⇒ Core
Returns a new instance of Core.
5 6 7 8 9 10 |
# File 'lib/fafx/core.rb', line 5 def initialize data = load_data @rates = data @dates = data.keys @currencies = @rates[@dates.first].keys end |
Instance Attribute Details
#currencies ⇒ Object (readonly)
Returns the value of attribute currencies.
4 5 6 |
# File 'lib/fafx/core.rb', line 4 def currencies @currencies end |
#dates ⇒ Object (readonly)
Returns the value of attribute dates.
4 5 6 |
# File 'lib/fafx/core.rb', line 4 def dates @dates end |
#rates ⇒ Object (readonly)
Returns the value of attribute rates.
4 5 6 |
# File 'lib/fafx/core.rb', line 4 def rates @rates end |
Instance Method Details
#rate(curr) ⇒ Object
12 13 14 15 |
# File 'lib/fafx/core.rb', line 12 def rate(curr) raise Fafx::CurrencyError, "#{curr} not found" unless @currencies.include?(curr) @rates[@dates.first][curr] end |
#rates_at(date, curr) ⇒ Object
17 18 19 20 21 |
# File 'lib/fafx/core.rb', line 17 def rates_at(date, curr) raise Fafx::DateError, 'Date not available' unless @dates.include?(date) raise Fafx::CurrencyError, "#{curr} not found" unless @currencies.include?(curr) @rates[date][curr] end |