Class: MudratProjector::DateDiff::YearCalculator

Inherits:
ComplexCalculator show all
Defined in:
lib/mudrat_projector/date_diff.rb

Instance Attribute Summary

Attributes inherited from ComplexCalculator

#first_unit

Attributes inherited from Calculator

#from, #to

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from ComplexCalculator

#calculate, #initialize

Methods inherited from Calculator

#calculate, #to_big_decimal

Constructor Details

This class inherits a constructor from MudratProjector::DateDiff::ComplexCalculator

Class Method Details

.advance(intervals, from: from) ⇒ Object



123
124
125
126
127
128
129
130
131
132
# File 'lib/mudrat_projector/date_diff.rb', line 123

def self.advance intervals, from: from
  if intervals < 1
    days_in_year = from.leap? ? 366 : 365
    days = intervals * days_in_year
    DayCalculator.advance days, from: from
  else
    method = intervals > 0 ? :next_year : :prev_year
    intervals.times.inject from do |date, _| date.public_send method; end
  end
end

Instance Method Details

#advance_one_unit(date) ⇒ Object



115
116
117
# File 'lib/mudrat_projector/date_diff.rb', line 115

def advance_one_unit date
  date.next_year
end

#fetch_unit(date) ⇒ Object



111
112
113
# File 'lib/mudrat_projector/date_diff.rb', line 111

def fetch_unit date
  (Date.new(date.year)..Date.new(date.year, 12, 31))
end

#rewind_one_unit(date) ⇒ Object



119
120
121
# File 'lib/mudrat_projector/date_diff.rb', line 119

def rewind_one_unit date
  date.prev_year
end