Class: CurrencyExchange::Transporters::ExchangeTransporter
- Inherits:
-
Object
- Object
- CurrencyExchange::Transporters::ExchangeTransporter
- Defined in:
- lib/currency_exchange/transporters/exchange_transporter.rb
Direct Known Subclasses
Constant Summary collapse
- TRANSPORTER_STRATEGY =
{ :json => CurrencyExchange::Transporters::JsonTransporter }
Class Method Summary collapse
Instance Method Summary collapse
- #fetch_data(url) ⇒ Object
-
#initialize ⇒ ExchangeTransporter
constructor
A new instance of ExchangeTransporter.
- #retrieve_rates(url) ⇒ Object
Constructor Details
#initialize ⇒ ExchangeTransporter
Returns a new instance of ExchangeTransporter.
7 8 9 |
# File 'lib/currency_exchange/transporters/exchange_transporter.rb', line 7 def initialize @storage = CurrencyExchange::Storage::Cache.instance end |
Class Method Details
.load_instance(transporter_strategy) ⇒ Object
19 20 21 |
# File 'lib/currency_exchange/transporters/exchange_transporter.rb', line 19 def self.load_instance(transporter_strategy) (TRANSPORTER_STRATEGY[transporter_strategy] || self).new end |
Instance Method Details
#fetch_data(url) ⇒ Object
15 16 17 |
# File 'lib/currency_exchange/transporters/exchange_transporter.rb', line 15 def fetch_data(url) raise NotImplementedError.new("fetch_data") end |
#retrieve_rates(url) ⇒ Object
11 12 13 |
# File 'lib/currency_exchange/transporters/exchange_transporter.rb', line 11 def retrieve_rates(url) @storage.fetch(url) || @storage.store(url, fetch_data(url)) end |