Class: ExchangeRateJt::ExchangeRates
- Inherits:
-
Object
- Object
- ExchangeRateJt::ExchangeRates
- Defined in:
- lib/exchange_rate_jt/exchange_rates.rb
Instance Method Summary collapse
- #at(date, base, counter) ⇒ Object
-
#initialize(configuration) ⇒ ExchangeRates
constructor
A new instance of ExchangeRates.
- #update ⇒ Object
Constructor Details
#initialize(configuration) ⇒ ExchangeRates
Returns a new instance of ExchangeRates.
12 13 14 |
# File 'lib/exchange_rate_jt/exchange_rates.rb', line 12 def initialize(configuration) @configuration = configuration end |
Instance Method Details
#at(date, base, counter) ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/exchange_rate_jt/exchange_rates.rb', line 24 def at(date, base, counter) validate_date(date) date = date.strftime('%b_%d_%Y').to_sym.downcase base = fetch_rate(date, base) counter = fetch_rate(date, counter) rate = (counter.to_f / base.to_f) * 10 { status: :success, rate: BigDecimal.new(rate, 5) } end |
#update ⇒ Object
16 17 18 19 20 21 22 |
# File 'lib/exchange_rate_jt/exchange_rates.rb', line 16 def update rates = RatesSourceFactory.build(configuration.source).fetch_rates rates.each { |date, values| data_store.persist(date, values) } true rescue => exception raise UpdateError, exception. end |