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

Methods inherited from Calculator

#to_big_decimal

Constructor Details

#initialize(*args) ⇒ ComplexCalculator

Returns a new instance of ComplexCalculator.



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

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.



65
66
67
# File 'lib/mudrat_projector/date_diff.rb', line 65

def first_unit
  @first_unit
end

Instance Method Details

#calculateObject



73
74
75
76
77
78
79
80
81
# File 'lib/mudrat_projector/date_diff.rb', line 73

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