mirror of
https://github.com/hakanensari/frankfurter.git
synced 2024-10-29 23:32:35 +01:00
31 lines
399 B
Ruby
31 lines
399 B
Ruby
require_relative 'db'
|
|
require 'yajl'
|
|
|
|
class Snapshot
|
|
def self.last
|
|
new Currency.last_date
|
|
end
|
|
|
|
def initialize(date)
|
|
@date = date
|
|
end
|
|
|
|
def to_base(base)
|
|
{
|
|
base: base,
|
|
date: @date,
|
|
rates: rates
|
|
}
|
|
end
|
|
|
|
private
|
|
|
|
def rates
|
|
Currency
|
|
.where(date: @date)
|
|
.reduce({}) { |hsh, currency|
|
|
hsh.update currency.to_hash
|
|
}
|
|
end
|
|
end
|