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, #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?

Constructor Details

This class inherits a constructor from SOF::Cycle

Class Method Details

.descriptionObject



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

def self.description
  "Lookback - occurrences within a prior time period counting backwards from today"
end

.examplesObject



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

def self.examples
  ["V3L3D - 3 times in the prior 3 days", "V1L2W - once in the prior 2 weeks"]
end

.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.



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

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

  window_end anchor
end

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



42
43
44
45
46
# File 'lib/sof/cycles/lookback.rb', line 42

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



49
50
51
# File 'lib/sof/cycles/lookback.rb', line 49

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

#to_sObject



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

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

#volume_to_delay_expiration(completion_dates, anchor:) ⇒ Object



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

def volume_to_delay_expiration(completion_dates, anchor:)
  relevant_dates = considered_dates(completion_dates, anchor:)
  return unless satisfied_by?(relevant_dates, anchor:)

  # To move the expiration date, we need to displace each occurance of the
  # oldest date within #considered_dates.
  relevant_dates.count(relevant_dates.min)
end