Class: Momm::Storage
- Inherits:
-
Object
- Object
- Momm::Storage
- Defined in:
- lib/momm/storage.rb
Direct Known Subclasses
Instance Method Summary collapse
-
#client ⇒ Object
Lazy load Client.
-
#get_rate(currency, date = Date.today) ⇒ Object
Fetch the currency rate from client.
-
#set_rate(currency, rate, date = Date.today) ⇒ Object
Insert the currency rate to client.
-
#update(data) ⇒ Object
update the data to storage.
Instance Method Details
#client ⇒ Object
Lazy load Client
Returns
Client
10 11 12 |
# File 'lib/momm/storage.rb', line 10 def client raise NotImplementedError end |
#get_rate(currency, date = Date.today) ⇒ Object
Fetch the currency rate from client
Parameters
- currency
-
Currency passed in
- date
-
Ruby date type, the date of currency rate, today by default
Returns
the currency rate
44 45 46 |
# File 'lib/momm/storage.rb', line 44 def get_rate(currency, date = Date.today) raise NotImplementedError end |
#set_rate(currency, rate, date = Date.today) ⇒ Object
Insert the currency rate to client
Parameters
- currency
-
Currency passed in, should be a symbol of iso code, such as :CNY, :USD, or :GBP
- rate
-
Fixnum represent for the currency rate from euro to certain currency
- date
-
Ruby date type, the date of currency rate, today by default
Returns
nil
29 30 31 |
# File 'lib/momm/storage.rb', line 29 def set_rate(currency, rate, date = Date.today) raise NotImplementedError end |
#update(data) ⇒ Object
update the data to storage
parameters
- data
-
An array looks like [Date.now, currency: :CNY, rate: 1.23 …]
Returns
“OK”
57 58 59 60 61 62 |
# File 'lib/momm/storage.rb', line 57 def update(data) data.each do |d| set_rate d[:currency], d[:rate], d[:date] end "OK" end |