From 696607470d8daf49258be9e6ef6fa7f9d28908a3 Mon Sep 17 00:00:00 2001 From: John Dowd Date: Wed, 4 Sep 2024 07:59:34 -0400 Subject: [PATCH] Add Cycle#notation_extended_by(count) For most Cycle types this just returns the original notation --- lib/sof/cycle.rb | 2 ++ spec/sof/cycles/calendar_spec.rb | 1 + spec/sof/cycles/end_of_spec.rb | 1 + spec/sof/cycles/lookback_spec.rb | 1 + spec/sof/cycles/shared_examples.rb | 6 ++++++ spec/sof/cycles/volume_only_spec.rb | 1 + 6 files changed, 12 insertions(+) diff --git a/lib/sof/cycle.rb b/lib/sof/cycle.rb index fe389d7..c507673 100644 --- a/lib/sof/cycle.rb +++ b/lib/sof/cycle.rb @@ -165,6 +165,8 @@ def ==(other) = to_h == other.to_h # Return the most recent completion date from the supplied array of dates def last_completed(dates) = dates.compact.map(&:to_date).max + def notation_extended_by(_ = nil) = notation + # From the supplied anchor date, are there enough in-window completions to # satisfy the cycle? # diff --git a/spec/sof/cycles/calendar_spec.rb b/spec/sof/cycles/calendar_spec.rb index f00437d..40fb395 100644 --- a/spec/sof/cycles/calendar_spec.rb +++ b/spec/sof/cycles/calendar_spec.rb @@ -32,6 +32,7 @@ module SOF it_behaves_like "it computes #final_date(given)", given: "1971-01-01", returns: "1971-12-31".to_date it_behaves_like "last_completed is", :recent_date + it_behaves_like "it cannot be extended" describe "#recurring?" do it "repeats" do diff --git a/spec/sof/cycles/end_of_spec.rb b/spec/sof/cycles/end_of_spec.rb index fb614c9..5a2c287 100644 --- a/spec/sof/cycles/end_of_spec.rb +++ b/spec/sof/cycles/end_of_spec.rb @@ -39,6 +39,7 @@ module SOF it_behaves_like "#as_json returns the notation" it_behaves_like "it computes #final_date(given)", given: nil, returns: ("2020-01-01".to_date + 17.months).end_of_month + it_behaves_like "it cannot be extended" describe "#last_completed" do context "with an activated cycle" do diff --git a/spec/sof/cycles/lookback_spec.rb b/spec/sof/cycles/lookback_spec.rb index d1c35d3..6cbda40 100644 --- a/spec/sof/cycles/lookback_spec.rb +++ b/spec/sof/cycles/lookback_spec.rb @@ -32,6 +32,7 @@ module SOF it_behaves_like "it computes #final_date(given)", given: "2003-03-08", returns: ("2003-03-08".to_date + 180.days) it_behaves_like "last_completed is", :recent_date + it_behaves_like "it cannot be extended" describe "#recurring?" do it "repeats" do diff --git a/spec/sof/cycles/shared_examples.rb b/spec/sof/cycles/shared_examples.rb index 5c553f1..145905e 100644 --- a/spec/sof/cycles/shared_examples.rb +++ b/spec/sof/cycles/shared_examples.rb @@ -51,3 +51,9 @@ expect(subject.last_completed(dates)).to eq(expected) end end + +shared_examples_for "it cannot be extended" do + it "returns its original notation" do + expect(subject.notation_extended_by(999)).to eq(subject.notation) + end +end diff --git a/spec/sof/cycles/volume_only_spec.rb b/spec/sof/cycles/volume_only_spec.rb index 9b8dd4a..552c2ab 100644 --- a/spec/sof/cycles/volume_only_spec.rb +++ b/spec/sof/cycles/volume_only_spec.rb @@ -30,6 +30,7 @@ module SOF it_behaves_like "it computes #final_date(given)", given: "2003-03-08", returns: nil it_behaves_like "last_completed is", :recent_date + it_behaves_like "it cannot be extended" describe "#recurring?" do it "does not repeat" do