Skip to content

Commit d0f186b

Browse files
committed
Add reactivated_notation alias and Within-parity specs
- reactivated_notation(date) aliases activated_notation for self-documenting call sites when re-anchoring a satisfied Interval - Specs verify Interval computes final_date/start_date identically to Within, documenting the conceptual relationship
1 parent c2e3ed1 commit d0f186b

3 files changed

Lines changed: 30 additions & 1 deletion

File tree

lib/sof/cycle.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,8 @@ def initialize(notation, parser: Parser.new(notation))
217217

218218
attr_reader :parser
219219

220-
delegate [:activated_notation, :volume, :from, :from_date, :time_span, :period,
220+
delegate [:activated_notation, :reactivated_notation, :volume, :from,
221+
:from_date, :time_span, :period,
221222
:humanized_period, :period_key, :active?] => :@parser
222223
delegate [:kind, :recurring?, :volume_only?, :valid_periods] => "self.class"
223224
delegate [:period_count, :duration] => :time_span

lib/sof/parser.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,8 @@ def activated_notation(date)
6666
self.class.load(to_h.merge(from_date: date.to_date)).notation
6767
end
6868

69+
alias_method :reactivated_notation, :activated_notation
70+
6971
def ==(other) = other.to_h == to_h
7072

7173
def to_h

spec/sof/cycles/interval_spec.rb

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,20 @@ module SOF
2424
end
2525
end
2626

27+
describe "relationship to Within" do
28+
# Interval uses the same window computation as Within but with
29+
# different lifecycle semantics (repeating vs one-shot)
30+
let(:within) { Cycle.for("V1W24MF#{from_date}") }
31+
32+
it "computes final_date the same as Within" do
33+
expect(cycle.final_date).to eq within.final_date
34+
end
35+
36+
it "computes start_date the same as Within" do
37+
expect(cycle.start_date).to eq within.start_date
38+
end
39+
end
40+
2741
@from = "2026-03-31".to_date.to_fs(:american)
2842
it_behaves_like "#to_s returns",
2943
"1x every 24 months from #{@from}"
@@ -146,6 +160,18 @@ module SOF
146160
end
147161
end
148162

163+
describe "#reactivated_notation" do
164+
it "returns a new notation with the updated from_date" do
165+
new_notation = cycle.reactivated_notation("2028-03-15".to_date)
166+
expect(new_notation).to eq "V1I24MF2028-03-15"
167+
end
168+
169+
it "is functionally identical to activated_notation" do
170+
date = "2028-06-01".to_date
171+
expect(cycle.reactivated_notation(date)).to eq cycle.activated_notation(date)
172+
end
173+
end
174+
149175
describe "activation" do
150176
let(:notation) { "V1I24M" }
151177

0 commit comments

Comments
 (0)