mirror of
https://github.com/hakanensari/frankfurter.git
synced 2024-11-25 12:32:30 +01:00
27 lines
420 B
Ruby
27 lines
420 B
Ruby
# frozen_string_literal: true
|
|
|
|
class Currency < Sequel::Model
|
|
dataset_module do
|
|
def recent
|
|
order(Sequel.desc(:date))
|
|
end
|
|
|
|
def before(value)
|
|
where { date <= value }
|
|
end
|
|
|
|
def current_date
|
|
currency = recent.first
|
|
currency.date if currency
|
|
end
|
|
|
|
def current_date_before(value)
|
|
before(value).current_date
|
|
end
|
|
end
|
|
|
|
def to_h
|
|
{ iso_code => rate }
|
|
end
|
|
end
|