Module: Timeprice::Granularity
- Defined in:
- lib/timeprice/granularity.rb
Overview
Closed set of CPI-resolution granularities and the rules for combining / rendering them. Owns the lattice so callers don’t hand-maintain it.
Constant Summary collapse
- DAILY =
:daily- MONTHLY =
:monthly- ANNUAL =
:annual- ANNUAL_FROM_MONTHLY_AVG =
:annual_from_monthly_avg- MONTHLY_FROM_ANNUAL_FALLBACK =
:monthly_from_annual_fallback- PRECEDENCE =
Most-degraded first — ‘merge` returns the first match. DAILY is the highest-precision FX tag; MONTHLY is the highest-precision CPI tag. Compare uses merge() across both legs, so the most-degraded tag in either leg wins.
[ MONTHLY_FROM_ANNUAL_FALLBACK, ANNUAL_FROM_MONTHLY_AVG, ANNUAL, MONTHLY, DAILY, ].freeze
- HUMAN_LABELS =
{ DAILY => "daily", MONTHLY => "monthly", ANNUAL => "annual", ANNUAL_FROM_MONTHLY_AVG => "annual (avg of months)", MONTHLY_FROM_ANNUAL_FALLBACK => "annual (month unavailable)", }.freeze
Class Method Summary collapse
-
.humanize(tag) ⇒ Object
Human-readable label for CLI output.
-
.merge(*tags) ⇒ Object
Worst-precision-wins merge across two or more endpoint granularities.
Class Method Details
.humanize(tag) ⇒ Object
Human-readable label for CLI output. Falls through to the symbol’s string form so an unknown tag still renders something.
42 43 44 |
# File 'lib/timeprice/granularity.rb', line 42 def humanize(tag) HUMAN_LABELS.fetch(tag, tag.to_s) end |
.merge(*tags) ⇒ Object
Worst-precision-wins merge across two or more endpoint granularities.
36 37 38 |
# File 'lib/timeprice/granularity.rb', line 36 def merge(*) PRECEDENCE.find { |t| .include?(t) } || MONTHLY end |