class TimeSpanner::TimeSpan
Attributes
unit_chain[R]
Public Class Methods
new(from, to, unit_names = [])
click to toggle source
# File lib/time_spanner/time_span.rb, line 8 def initialize from, to, unit_names = [] validate! from, to units = TimeUnitCollector.new( unit_names ).units @unit_chain = DurationChain.new from.to_time, to.to_time, units build! end
Private Instance Methods
build!()
click to toggle source
# File lib/time_spanner/time_span.rb, line 20 def build! unit_chain.each do |unit| self[ unit.plural_name ] = unit.amount end end
validate!(from, to)
click to toggle source
# File lib/time_spanner/time_span.rb, line 26 def validate! from, to unless [ from, to ].all? { |obj| obj.is_a?( Time ) || ( obj.respond_to?( :to_time ) && obj.to_time.is_a?( Time ) ) } raise InvalidClassError, "Must convert to Time object!" end end