Class: Core

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeCore

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

#currenciesObject (readonly)

Returns the value of attribute currencies.



4
5
6
# File 'lib/fafx/core.rb', line 4

def currencies
  @currencies
end

#datesObject (readonly)

Returns the value of attribute dates.



4
5
6
# File 'lib/fafx/core.rb', line 4

def dates
  @dates
end

#ratesObject (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

Raises:



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