Class: SOF::Cycles::Lookback

Inherits:
SOF::Cycle show all
Defined in:
lib/sof/cycles/lookback.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, #cover?, #covered_dates, cycle_handlers, dump, #extend_period, for, #from_data, handles?, #humanized_span, inherited, #initialize, #kind_inquiry, #last_completed, load, #notation, notation, #range, #satisfied_by?, #to_h, validate_period, #validate_period, volume_only?

Constructor Details

This class inherits a constructor from SOF::Cycle

Class Method Details

.recurring?Boolean

Returns:

  • (Boolean)


11
# File 'lib/sof/cycles/lookback.rb', line 11

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.



23
24
25
26
27
28
# File 'lib/sof/cycles/lookback.rb', line 23

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

  window_end anchor
end

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



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

def final_date(anchor)
  return if anchor.nil?

  time_span.end_date(anchor.to_date)
end

#start_date(anchor) ⇒ Object Also known as: window_start



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

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

#to_sObject



13
# File 'lib/sof/cycles/lookback.rb', line 13

def to_s = "#{volume}x in the prior #{period_count} #{humanized_period}"

#volume_to_delay_expiration(completion_dates, anchor:) ⇒ Object



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

def volume_to_delay_expiration(completion_dates, anchor:)
  oldest_relevant_completion = completion_dates.min
  [completion_dates.count(oldest_relevant_completion), volume].min
end