Class: MudratProjector::DateDiff::ComplexCalculator

Inherits:
Calculator
  • Object
show all
Defined in:
lib/mudrat_projector/date_diff.rb

Instance Attribute Summary collapse

Attributes inherited from Calculator

#from, #to

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ ComplexCalculator

Returns a new instance of ComplexCalculator.



59
60
61
62
63
# File 'lib/mudrat_projector/date_diff.rb', line 59

def initialize *args
  super
  @first_unit = fetch_unit from
  @last_unit  = fetch_unit to
end

Instance Attribute Details

#first_unitObject (readonly)

Returns the value of attribute first_unit.



57
58
59
# File 'lib/mudrat_projector/date_diff.rb', line 57

def first_unit
  @first_unit
end

Instance Method Details

#calculateObject



65
66
67
68
69
70
71
72
73
# File 'lib/mudrat_projector/date_diff.rb', line 65

def calculate
  if first_unit.begin == last_unit.begin
    days_between / days_in_unit(first_unit)
  else
    calculate_unit(from, first_unit.end) +
      units_between +
      calculate_unit(last_unit.begin, to)
  end
end