Class: Momm::Storage

Inherits:
Object
  • Object
show all
Defined in:
lib/momm/storage.rb

Direct Known Subclasses

Memcached, RedisStore

Instance Method Summary collapse

Instance Method Details

#clientObject

Lazy load Client

Returns

Client

Raises:

  • (NotImplementedError)


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

Raises:

  • (NotImplementedError)


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

Raises:

  • (NotImplementedError)


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