frankfurter/lib/peg.rb
BadMark d0a43e357a
Some checks failed
CI/CD Pipeline / test (push) Has been cancelled
CI/CD Pipeline / publish (push) Has been cancelled
CI/CD Pipeline / release (push) Has been cancelled
up
2026-05-21 01:38:14 -06:00

28 lines
670 B
Ruby

# frozen_string_literal: true
require "json"
Peg = Data.define(:quote, :base, :rate, :since, :authority, :source) do
class << self
def all
@all ||= begin
dir = File.expand_path("../db/seeds/pegs", __dir__)
Dir["#{dir}/*.json"].sort.map do |f|
h = JSON.parse(File.read(f))
new(
quote: h["quote"],
base: h["base"],
rate: h.fetch("rate", 1.0),
since: Date.parse(h["since"]),
authority: h["authority"],
source: h["source"],
)
end.freeze
end
end
def find(quote)
all.find { |p| p.quote == quote }
end
end
end