Class: MudratProjector::DateDiff::MonthCalculator

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



173
174
175
176
177
178
179
180
181
# File 'lib/mudrat_projector/date_diff.rb', line 173

def self.advance intervals, from: from
  if intervals < 1
    days_in_month = Date.new(from.year, from.month, -1).day
    days = intervals * days_in_month
    DayCalculator.advance days, from: from
  else
    intervals.times.inject from do |date, _| date.next_month; end
  end
end

Instance Method Details

#advance_one_unit(date) ⇒ Object



165
166
167
# File 'lib/mudrat_projector/date_diff.rb', line 165

def advance_one_unit date
  date.next_month
end

#fetch_unit(date) ⇒ Object



160
161
162
163
# File 'lib/mudrat_projector/date_diff.rb', line 160

def fetch_unit date
  start_of_month = Date.new(date.year, date.month)
  (start_of_month..(start_of_month.next_month - 1))
end

#rewind_one_unit(date) ⇒ Object



169
170
171
# File 'lib/mudrat_projector/date_diff.rb', line 169

def rewind_one_unit date
  date.prev_month
end