Skip to content

Commit

Permalink
Add Cycles::Within#notation_extended_by(count)
Browse files Browse the repository at this point in the history
  • Loading branch information
jdowd committed Sep 4, 2024
1 parent 6966074 commit 62f9de9
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
7 changes: 7 additions & 0 deletions lib/sof/cycles/within.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,13 @@ def self.recurring? = false

def to_s = "#{volume}x within #{date_range}"

def notation_extended_by(count)
Parser.load(
parser.to_h.merge(period_count: period_count + count)
).to_s
end
alias_method :grant_extension, :notation_extended_by

def date_range
return humanized_span unless active?

Expand Down
11 changes: 11 additions & 0 deletions spec/sof/cycles/within_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,17 @@ module SOF
given: "_", returns: ("2020-08-01".to_date + 180.days)
it_behaves_like "last_completed is", :too_late

describe "#notation_extended_by" do
it "increases the period by the given amount" do
aggregate_failures do
expect(cycle.notation).to eq("V2W180DF2020-08-01")

notation = cycle.notation_extended_by(30)
expect(notation).to eq("V2W210DF2020-08-01")
end
end
end

describe "#recurring?" do
it "does not repeat" do
expect(cycle).not_to be_recurring
Expand Down

0 comments on commit 62f9de9

Please sign in to comment.