Class: SOF::Cycles::Interval

Inherits:
SOF::Cycle show all
Defined in:
lib/sof/cycles/interval.rb

Constant Summary

Constants inherited from SOF::Cycle

SOF::Cycle::VERSION

Instance Attribute Summary

Attributes inherited from SOF::Cycle

#parser

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from SOF::Cycle

#==, #as_json, class_for_kind, class_for_notation_id, #considered_dates, #cover?, #covered_dates, cycle_handlers, dump, #extend_period, for, #from_data, handles?, #humanized_span, inherited, #initialize, #kind_inquiry, legend, load, notation, #notation, #range, #to_h, validate_period, #validate_period, volume_only?, #volume_to_delay_expiration

Constructor Details

This class inherits a constructor from SOF::Cycle

Class Method Details

.descriptionObject



23
24
25
# File 'lib/sof/cycles/interval.rb', line 23

def self.description
  "Interval - occurrences within a repeating window that re-anchors from completion date"
end

.dormant_capable?Boolean

Returns:

  • (Boolean)


21
# File 'lib/sof/cycles/interval.rb', line 21

def self.dormant_capable? = true

.examplesObject



27
28
29
# File 'lib/sof/cycles/interval.rb', line 27

def self.examples
  ["V1I24MF2026-03-31 - once every 24 months from March 31, 2026 (re-anchors after completion)"]
end

.recurring?Boolean

Returns:

  • (Boolean)


19
# File 'lib/sof/cycles/interval.rb', line 19

def self.recurring? = true

Instance Method Details

#expiration_of(_ = nil, anchor: nil) ⇒ Date?

Returns the expiration date for the current window

Returns:

  • (Date, nil)

    The final date of the current window



40
41
42
# File 'lib/sof/cycles/interval.rb', line 40

def expiration_of(_ = nil, anchor: nil)
  final_date
end

#final_date(_ = nil) ⇒ Date

Calculates the final date of the current window

Examples:

Cycle.for("V1I24MF2026-03-31").final_date
# => #<Date: 2028-03-31>

Returns:

  • (Date)

    from_date + period (no end-of-month rounding)



61
62
63
64
# File 'lib/sof/cycles/interval.rb', line 61

def final_date(_ = nil)
  return nil if start_date.nil?
  time_span.end_date(start_date)
end

#last_completed(_ = nil) ⇒ Object

Returns the from_date as the last completed date



52
# File 'lib/sof/cycles/interval.rb', line 52

def last_completed(_ = nil) = from_date&.to_date

#satisfied_by?(_ = nil, anchor: Date.current) ⇒ Boolean

Is the supplied anchor date within the current window?

Returns:

  • (Boolean)

    true if the anchor is before or on the final date



47
48
49
# File 'lib/sof/cycles/interval.rb', line 47

def satisfied_by?(_ = nil, anchor: Date.current)
  anchor <= final_date
end

#start_date(_ = nil) ⇒ Object



66
# File 'lib/sof/cycles/interval.rb', line 66

def start_date(_ = nil) = from_date&.to_date

#to_sObject



31
32
33
34
35
# File 'lib/sof/cycles/interval.rb', line 31

def to_s
  return dormant_to_s unless active?

  "#{volume}x every #{humanized_span} from #{start_date.to_fs(:american)}"
end