Class: SOF::Cycles::Calendar

Inherits:
SOF::Cycle show all
Defined in:
lib/sof/cycles/calendar.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, dormant_capable?, #dormant_capable?, dump, #extend_period, for, #from_data, handles, handles?, #humanized_span, #initialize, #kind_inquiry, #last_completed, legend, load, notation, #notation, #range, register, registry, #reset_by, #satisfied_by?, #to_h, unregister, validate_period, #validate_period, volume_only?, #volume_to_delay_expiration

Constructor Details

This class inherits a constructor from SOF::Cycle

Class Method Details

.descriptionObject



11
12
13
# File 'lib/sof/cycles/calendar.rb', line 11

def description
  "Calendar - occurrences within the current calendar period"
end

.examplesObject



15
16
17
# File 'lib/sof/cycles/calendar.rb', line 15

def examples
  ["V2C1M - twice this calendar month", "V4C1Y - 4 times this calendar year"]
end

.frame_of_referenceObject



9
# File 'lib/sof/cycles/calendar.rb', line 9

def frame_of_reference = "total"

.recurring?Boolean

Returns:

  • (Boolean)


20
# File 'lib/sof/cycles/calendar.rb', line 20

def self.recurring? = true

Instance Method Details

#expiration_of(completion_dates) ⇒ Date?

"Absent further completions, you go red on this date"

Returns:

  • (Date, nil)

    the date on which the cycle will expire given the provided completion dates. Returns nil if the cycle is already unsatisfied.



29
30
31
32
33
34
# File 'lib/sof/cycles/calendar.rb', line 29

def expiration_of(completion_dates)
  anchor = completion_dates.max_by(volume) { it }.min
  return unless satisfied_by?(completion_dates, anchor:)

  window_end(anchor) + duration
end

#final_date(anchor) ⇒ Object Also known as: window_end



36
37
38
39
# File 'lib/sof/cycles/calendar.rb', line 36

def final_date(anchor)
  return if anchor.nil?
  time_span.end_date_of_period(anchor.to_date)
end

#start_date(anchor) ⇒ Object



42
43
44
# File 'lib/sof/cycles/calendar.rb', line 42

def start_date(anchor)
  time_span.begin_date_of_period(anchor.to_date)
end

#to_sObject



22
23
24
# File 'lib/sof/cycles/calendar.rb', line 22

def to_s
  "#{volume}x every #{period_count} calendar #{humanized_period}"
end