module TimePieces::Duration
Attributes
duration_seconds[RW]
lane_count[RW]
lane_number[RW]
start_at_seconds[RW]
Public Class Methods
included(base)
click to toggle source
# File lib/time_pieces/duration.rb, line 11 def self.included(base) base.extend(DurationClassMethods) end
Public Instance Methods
+(other_td)
click to toggle source
# File lib/time_pieces/duration.rb, line 78 def +(other_td) ts_ret = TimeSet.new if overlaps?(other_td) if overlaps_start?(other_td) && !overlaps_outside?(other_td) update_start_seconds_and_end_seconds(other_td.start_at_seconds, end_at_seconds) ts_ret << self return ts_ret end if overlaps_end?(other_td) && !overlaps_outside?(other_td) update_start_seconds_and_end_seconds(start_at_seconds, other_td.end_at_seconds) ts_ret << self return ts_ret end if overlaps_inside?(other_td) ts_ret << self return ts_ret end if overlaps_outside?(other_td) ts_ret << other_td end return ts_ret end if touches?(other_td) if touches_at_end?(other_td) && other_td.end_at_seconds > end_at_seconds update_start_seconds_and_end_seconds(start_at_seconds, other_td.end_at_seconds) ts_ret << self return ts_ret end if touches_at_start?(other_td) && other_td.start_at_seconds < start_at_seconds update_start_seconds_and_end_seconds(other_td.start_at_seconds, end_at_seconds) ts_ret << self return ts_ret end return false end ts_ret << self ts_ret << other_td return ts_ret end
-(other_td)
click to toggle source
# File lib/time_pieces/duration.rb, line 118 def -(other_td) ts_ret = TimeSet.new return ts_ret if inside_of?(other_td) unless overlaps?(other_td) ts_ret << self return ts_ret end if overlaps?(other_td) if overlaps_start?(other_td) update_start_seconds_and_end_seconds(other_td.end_at_seconds, end_at_seconds) ts_ret << self return ts_ret end if overlaps_end?(other_td) puts inspect update_start_seconds_and_end_seconds(start_at_seconds, other_td.start_at_seconds) puts "RUNNING OVERLAPPING END" puts inspect ts_ret << self return ts_ret end if overlaps_inside?(other_td) left_of_break = left_duration_copy.update_start_seconds_and_end_seconds(start_at_seconds, other_td.start_at_seconds) right_of_break = right_duration_copy.update_start_seconds_and_end_seconds(other_td.end_at_seconds, end_at_seconds) ts_ret << left_of_break ts_ret << right_of_break end return ts_ret end end
<=>(other)
click to toggle source
# File lib/time_pieces/duration.rb, line 75 def <=>(other) start_at_seconds <=> other.start_at_seconds end
clip!(start_at_seconds, end_at_seconds)
click to toggle source
# File lib/time_pieces/duration.rb, line 31 def clip!(start_at_seconds, end_at_seconds) self.start_at_seconds = start_at_seconds if self.start_at_seconds < start_at_seconds if self.start_at_seconds + self.duration_seconds > end_at_seconds self.duration_seconds = end_at_seconds - start_at_seconds end end
end_at_seconds()
click to toggle source
# File lib/time_pieces/duration.rb, line 14 def end_at_seconds return start_at_seconds + duration_seconds end
end_at_seconds=(new_end_at_seconds)
click to toggle source
# File lib/time_pieces/duration.rb, line 17 def end_at_seconds=(new_end_at_seconds) self.duration_seconds = new_end_at_seconds - start_at_seconds end
inside_of?(other_td)
click to toggle source
# File lib/time_pieces/duration.rb, line 50 def inside_of?(other_td) return true if (other_td.start_at_seconds < start_at_seconds) && (other_td.end_at_seconds > end_at_seconds) end
left_duration_copy()
click to toggle source
# File lib/time_pieces/duration.rb, line 25 def left_duration_copy duration_copy end
overlaps?(other_td)
click to toggle source
# File lib/time_pieces/duration.rb, line 56 def overlaps?(other_td) return true if overlaps_outside?(other_td) return true if overlaps_start?(other_td) return true if overlaps_end?(other_td) return true if overlaps_inside?(other_td) return false end
overlaps_end?(other_td)
click to toggle source
# File lib/time_pieces/duration.rb, line 42 def overlaps_end?(other_td) return true if (end_at_seconds <= other_td.end_at_seconds) && (end_at_seconds > other_td.start_at_seconds) return false end
overlaps_inside?(other_td)
click to toggle source
# File lib/time_pieces/duration.rb, line 46 def overlaps_inside?(other_td) return true if (other_td.end_at_seconds > start_at_seconds) && (other_td.end_at_seconds <= end_at_seconds) && (other_td.start_at_seconds >= start_at_seconds) && (other_td.start_at_seconds < end_at_seconds) return false end
overlaps_outside?(other_td)
click to toggle source
# File lib/time_pieces/duration.rb, line 53 def overlaps_outside?(other_td) return other_td.overlaps_inside?(self) end
overlaps_start?(other_td)
click to toggle source
# File lib/time_pieces/duration.rb, line 38 def overlaps_start?(other_td) return true if (start_at_seconds >= other_td.start_at_seconds) && (start_at_seconds < other_td.end_at_seconds) return false end
right_duration_copy()
click to toggle source
# File lib/time_pieces/duration.rb, line 28 def right_duration_copy duration_copy end
touches?(other_td)
click to toggle source
# File lib/time_pieces/duration.rb, line 71 def touches?(other_td) return (touches_at_start?(other_td) || touches_at_end?(other_td)) return false end
touches_at_end?(other_td)
click to toggle source
# File lib/time_pieces/duration.rb, line 67 def touches_at_end?(other_td) return true if other_td.start_at_seconds == end_at_seconds return false end
touches_at_start?(other_td)
click to toggle source
# File lib/time_pieces/duration.rb, line 63 def touches_at_start?(other_td) return true if other_td.end_at_seconds == start_at_seconds return false end
update_start_seconds_and_end_seconds(new_start_seconds, new_end_seconds)
click to toggle source
# File lib/time_pieces/duration.rb, line 20 def update_start_seconds_and_end_seconds(new_start_seconds, new_end_seconds) self.start_at_seconds = new_start_seconds self.end_at_seconds = new_end_seconds return self end