Class: TimeSpanner::TimeUnits::CalendarUnit

Inherits:
Unit
  • Object
show all
Defined in:
lib/time_spanner/time_units/base/calendar_unit.rb

Direct Known Subclasses

Century, Day, Decade, Millennium, Month, Week, Year

Instance Attribute Summary collapse

Attributes inherited from Unit

#amount, #duration, #position, #rest

Instance Method Summary collapse

Methods inherited from Unit

#<=>, #plural_name, #reverse!

Constructor Details

#initialize(position) ⇒ CalendarUnit

Returns a new instance of CalendarUnit.



8
9
10
# File 'lib/time_spanner/time_units/base/calendar_unit.rb', line 8

def initialize position
  super position
end

Instance Attribute Details

#fromObject (readonly)

Returns the value of attribute from.



6
7
8
# File 'lib/time_spanner/time_units/base/calendar_unit.rb', line 6

def from
  @from
end

#toObject (readonly)

Returns the value of attribute to.



6
7
8
# File 'lib/time_spanner/time_units/base/calendar_unit.rb', line 6

def to
  @to
end

Instance Method Details

#calculate(duration, to) ⇒ Object



12
13
14
15
16
17
18
# File 'lib/time_spanner/time_units/base/calendar_unit.rb', line 12

def calculate duration, to
  @to       = to
  @from     = @to - duration.to_r

  calculate_amount
  calculate_rest at_amount( amount )
end