class TimeSpanner::DurationChain
Attributes
remaining[RW]
reverse[RW]
reverse?[RW]
to[R]
units[RW]
Public Class Methods
new(from, to, units)
click to toggle source
# File lib/time_spanner/duration_chain.rb, line 14 def initialize from, to, units @from, @to = setup_times from, to @remaining = to.to_r - from.to_r @units = units.map &:new calculate! end
Private Instance Methods
calculate!()
click to toggle source
Perform duration calculations for units in chain.
# File lib/time_spanner/duration_chain.rb, line 25 def calculate! sort! each do |unit| calculate_unit unit end end
calculate_unit(unit)
click to toggle source
# File lib/time_spanner/duration_chain.rb, line 33 def calculate_unit unit unit.calculate remaining, to unit.reverse! if reverse? @remaining = unit.rest end
setup_times(from, to)
click to toggle source
# File lib/time_spanner/duration_chain.rb, line 45 def setup_times from, to @reverse = to < from new_from = reverse? ? to : from new_to = reverse? ? from : to [ new_from, new_to ] end
sort!()
click to toggle source
Units must be sorted to perform a correct calculation chain.
# File lib/time_spanner/duration_chain.rb, line 41 def sort! @units = units.sort end