Class: SOF::Cycles::EndOf

Inherits:
SOF::Cycle show all
Defined in:
lib/sof/cycles/end_of.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, 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

.recurring?Boolean

Returns:

  • (Boolean)


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

def self.recurring? = true

Instance Method Details

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

Returns the expiration date for the cycle

Examples:

Cycle.for("V1E18MF2020-01-09")
  .expiration_of(anchor: "2020-06-04".to_date)
# => #<Date: 2021-06-30>

Parameters:

  • _ (nil) (defaults to: nil)

    Unused parameter, maintained for compatibility

  • anchor (nil) (defaults to: nil)

    _ Unused parameter, maintained for compatibility

Returns:

  • (Date)

    The final date of the cycle



40
# File 'lib/sof/cycles/end_of.rb', line 40

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

#final_date(_ = nil) ⇒ Date

Calculates the final date of the cycle

Examples:

Cycle.for("V1E18MF2020-01-09").final_date
# => #<Date: 2021-06-30>

Parameters:

  • _ (nil) (defaults to: nil)

    Unused parameter, maintained for compatibility

Returns:

  • (Date)

    The final date of the cycle calculated as the end of the nth subsequent period after the FROM date, where n = (period count - 1)



56
57
58
# File 'lib/sof/cycles/end_of.rb', line 56

def final_date(_ = nil) = time_span
.end_date(start_date - 1.send(period))
.end_of_month

#last_completed(_ = nil) ⇒ Object

Always returns the from_date



28
# File 'lib/sof/cycles/end_of.rb', line 28

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

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

Is the supplied anchor date prior to the final date?

Returns:

  • (Boolean)

    true if the cycle is satisfied, false otherwise



45
# File 'lib/sof/cycles/end_of.rb', line 45

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

#start_date(_ = nil) ⇒ Object



60
# File 'lib/sof/cycles/end_of.rb', line 60

def start_date(_ = nil) = from_date.to_date

#to_sObject



21
22
23
24
25
# File 'lib/sof/cycles/end_of.rb', line 21

def to_s
  return dormant_to_s if dormant?

  "#{volume}x by #{final_date.to_fs(:american)}"
end