From e49bd16c12113e9d000e95627fac1d03bc0fa768 Mon Sep 17 00:00:00 2001 From: "ryan.weiss" Date: Thu, 19 Mar 2026 22:06:35 -0700 Subject: [PATCH] Move dormant_capable? from Parser to cycle classes MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Each cycle class now declares its own dormant capability: def self.dormant_capable? = true # EndOf, Within def self.dormant_capable? = false # Cycle base (default) Parser.dormant_capable_kinds now derives the list from Cycle.cycle_handlers instead of a hardcoded array. This means adding a new dormant-capable cycle kind only requires declaring dormant_capable? on the class — no separate Parser edit needed. --- CHANGELOG.md | 4 ++++ lib/sof/cycle.rb | 2 ++ lib/sof/cycles/end_of.rb | 2 ++ lib/sof/cycles/within.rb | 2 ++ lib/sof/parser.rb | 4 +++- 5 files changed, 13 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c602b14..035b942 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [0.1.13] - Unreleased +### Changed + +- Dormant capability is now declared on each cycle class (`def self.dormant_capable? = true`) instead of only in `Parser.dormant_capable_kinds` + ## [0.1.12] - 2025-09-05 ### Added diff --git a/lib/sof/cycle.rb b/lib/sof/cycle.rb index 9adf732..0010e51 100644 --- a/lib/sof/cycle.rb +++ b/lib/sof/cycle.rb @@ -130,6 +130,8 @@ def legend attr_reader :notation_id, :kind, :valid_periods def volume_only? = @volume_only + def dormant_capable? = false + def recurring? = raise "#{name} must implement #{__method__}" # Raises an error if the given period isn't in the list of valid periods. diff --git a/lib/sof/cycles/end_of.rb b/lib/sof/cycles/end_of.rb index b86c572..310f257 100644 --- a/lib/sof/cycles/end_of.rb +++ b/lib/sof/cycles/end_of.rb @@ -18,6 +18,8 @@ class EndOf < Cycle def self.recurring? = true + def self.dormant_capable? = true + def self.description "End of - occurrences by the end of a time period" end diff --git a/lib/sof/cycles/within.rb b/lib/sof/cycles/within.rb index d3120cd..05ab165 100644 --- a/lib/sof/cycles/within.rb +++ b/lib/sof/cycles/within.rb @@ -10,6 +10,8 @@ class Within < Cycle def self.recurring? = false + def self.dormant_capable? = true + def self.description "Within - occurrences within a time period from a specific date" end diff --git a/lib/sof/parser.rb b/lib/sof/parser.rb index 967fd45..cdc9b3b 100644 --- a/lib/sof/parser.rb +++ b/lib/sof/parser.rb @@ -20,7 +20,9 @@ class Parser (?F(?\d{4}-\d{2}-\d{2}))?$ # optional from /ix - def self.dormant_capable_kinds = %w[E W] + def self.dormant_capable_kinds + Cycle.cycle_handlers.select(&:dormant_capable?).map(&:notation_id).compact + end def self.for(notation_or_parser) return notation_or_parser if notation_or_parser.is_a? self