Class: Biz::TimeSegment
- Inherits:
-
Object
- Object
- Biz::TimeSegment
- Defined in:
- lib/biz/time_segment.rb
Instance Attribute Summary collapse
-
#end_time ⇒ Object
readonly
Returns the value of attribute end_time.
-
#start_time ⇒ Object
readonly
Returns the value of attribute start_time.
Class Method Summary collapse
Instance Method Summary collapse
- #&(other) ⇒ Object
- #/(other) ⇒ Object
- #contains?(time) ⇒ Boolean
- #duration ⇒ Object
- #empty? ⇒ Boolean
- #endpoints ⇒ Object
-
#initialize(start_time, end_time) ⇒ TimeSegment
constructor
A new instance of TimeSegment.
Constructor Details
#initialize(start_time, end_time) ⇒ TimeSegment
Returns a new instance of TimeSegment.
17 18 19 20 |
# File 'lib/biz/time_segment.rb', line 17 def initialize(start_time, end_time) @start_time = start_time @end_time = end_time end |
Instance Attribute Details
#end_time ⇒ Object (readonly)
Returns the value of attribute end_time.
14 15 16 |
# File 'lib/biz/time_segment.rb', line 14 def end_time @end_time end |
#start_time ⇒ Object (readonly)
Returns the value of attribute start_time.
14 15 16 |
# File 'lib/biz/time_segment.rb', line 14 def start_time @start_time end |
Class Method Details
.after(time) ⇒ Object
10 11 12 |
# File 'lib/biz/time_segment.rb', line 10 def self.after(time) new(time, Time::HEAT_DEATH) end |
Instance Method Details
#&(other) ⇒ Object
38 39 40 41 42 43 |
# File 'lib/biz/time_segment.rb', line 38 def &(other) self.class.new( lower_bound(other), [lower_bound(other), upper_bound(other)].max ) end |
#/(other) ⇒ Object
45 46 47 48 49 50 |
# File 'lib/biz/time_segment.rb', line 45 def /(other) [ self.class.new(start_time, other.start_time), self.class.new(other.end_time, end_time) ].reject(&:empty?).map { |potential| self & potential } end |
#contains?(time) ⇒ Boolean
34 35 36 |
# File 'lib/biz/time_segment.rb', line 34 def contains?(time) (start_time..end_time).cover?(time) end |
#duration ⇒ Object
22 23 24 |
# File 'lib/biz/time_segment.rb', line 22 def duration Duration.new(end_time - start_time) end |
#empty? ⇒ Boolean
30 31 32 |
# File 'lib/biz/time_segment.rb', line 30 def empty? start_time >= end_time end |
#endpoints ⇒ Object
26 27 28 |
# File 'lib/biz/time_segment.rb', line 26 def endpoints [start_time, end_time] end |