class Biz::TimeSegment
Attributes
date[R]
end_time[R]
start_time[R]
Public Class Methods
after(time)
click to toggle source
# File lib/biz/time_segment.rb, line 12 def self.after(time) new(time, Time.heat_death) end
before(time)
click to toggle source
# File lib/biz/time_segment.rb, line 8 def self.before(time) new(Time.big_bang, time) end
new(start_time, end_time)
click to toggle source
# File lib/biz/time_segment.rb, line 16 def initialize(start_time, end_time) @start_time = start_time @end_time = end_time @date = start_time.to_date end
Public Instance Methods
&(other)
click to toggle source
# File lib/biz/time_segment.rb, line 46 def &(other) self.class.new( [self, other].map(&:start_time).max, [self, other].map(&:end_time).min ) end
/(other)
click to toggle source
# File lib/biz/time_segment.rb, line 53 def /(other) [ self.class.new(start_time, other.start_time), self.class.new(other.end_time, end_time) ].reject(&:disjoint?).map { |potential| self & potential } end
contains?(time)
click to toggle source
# File lib/biz/time_segment.rb, line 42 def contains?(time) (start_time...end_time).cover?(time) end
disjoint?()
click to toggle source
# File lib/biz/time_segment.rb, line 38 def disjoint? start_time > end_time end
duration()
click to toggle source
# File lib/biz/time_segment.rb, line 26 def duration Duration.new([end_time - start_time, 0].max) end
empty?()
click to toggle source
# File lib/biz/time_segment.rb, line 34 def empty? start_time == end_time end
endpoints()
click to toggle source
# File lib/biz/time_segment.rb, line 30 def endpoints [start_time, end_time] end
Private Instance Methods
<=>(other)
click to toggle source
# File lib/biz/time_segment.rb, line 62 def <=>(other) return unless other.is_a?(self.class) [start_time, end_time] <=> [other.start_time, other.end_time] end