frankfurter/lib/currency.rb

26 lines
383 B
Ruby
Raw Normal View History

2015-12-30 20:52:02 +01:00
# frozen_string_literal: true
2017-06-14 22:16:21 +02:00
2012-11-20 17:36:12 +01:00
class Currency < Sequel::Model
2015-08-30 11:36:32 +02:00
dataset_module do
def recent
order(Sequel.desc(:date))
end
def before(value)
where { date <= value }
end
def current_date
2016-10-11 17:54:28 +02:00
recent.first&.date
2015-08-30 11:36:32 +02:00
end
def current_date_before(value)
before(value).current_date
end
2012-11-20 17:36:12 +01:00
end
2015-08-31 11:56:01 +02:00
def to_h
2012-11-20 17:36:12 +01:00
{ iso_code => rate }
end
end