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, cycle_handlers, dump, #extend_period, for, #from_data, handles?, #humanized_span, inherited, #initialize, #kind_inquiry, #last_completed, legend, load, notation, #notation, #range, #satisfied_by?, #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



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

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

.examplesObject



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

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

.frame_of_referenceObject



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

def frame_of_reference = "total"

.recurring?Boolean

Returns:

  • (Boolean)


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

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.



32
33
34
35
36
37
# File 'lib/sof/cycles/calendar.rb', line 32

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



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

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

#start_date(anchor) ⇒ Object



45
46
47
# File 'lib/sof/cycles/calendar.rb', line 45

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

#to_sObject



25
26
27
# File 'lib/sof/cycles/calendar.rb', line 25

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