Class: Availabiliter::TimeSlot
- Inherits:
-
Object
- Object
- Availabiliter::TimeSlot
- Defined in:
- lib/availabiliter/time_slot.rb
Overview
A TimeSlot represent a slot in time with a start and an end that can be finite or infinite. It can also act as a boundary in availabilities calculation.
Instance Attribute Summary collapse
-
#boundary ⇒ Object
readonly
Returns the value of attribute boundary.
-
#ending_time ⇒ Object
readonly
Returns the value of attribute ending_time.
-
#starting_time ⇒ Object
readonly
Returns the value of attribute starting_time.
Instance Method Summary collapse
- #adjacent?(other) ⇒ Boolean
- #dependent?(other) ⇒ Boolean
- #does_not_overlap?(other) ⇒ Boolean
- #furthest(other) ⇒ Object
-
#initialize(starting_time:, ending_time:, boundary: false) ⇒ TimeSlot
constructor
A new instance of TimeSlot.
- #next_second ⇒ Object
- #overlaps?(other) ⇒ Boolean
- #previous_second ⇒ Object
Constructor Details
#initialize(starting_time:, ending_time:, boundary: false) ⇒ TimeSlot
Returns a new instance of TimeSlot.
7 8 9 10 11 12 |
# File 'lib/availabiliter/time_slot.rb', line 7 def initialize(starting_time:, ending_time:, boundary: false) @starting_time = starting_time @ending_time = ending_time @boundary = boundary validate end |
Instance Attribute Details
#boundary ⇒ Object (readonly)
Returns the value of attribute boundary.
5 6 7 |
# File 'lib/availabiliter/time_slot.rb', line 5 def boundary @boundary end |
#ending_time ⇒ Object (readonly)
Returns the value of attribute ending_time.
5 6 7 |
# File 'lib/availabiliter/time_slot.rb', line 5 def ending_time @ending_time end |
#starting_time ⇒ Object (readonly)
Returns the value of attribute starting_time.
5 6 7 |
# File 'lib/availabiliter/time_slot.rb', line 5 def starting_time @starting_time end |
Instance Method Details
#adjacent?(other) ⇒ Boolean
38 39 40 |
# File 'lib/availabiliter/time_slot.rb', line 38 def adjacent?(other) other.ending_time == previous_second || other.starting_time == next_second end |
#dependent?(other) ⇒ Boolean
18 19 20 |
# File 'lib/availabiliter/time_slot.rb', line 18 def dependent?(other) adjacent?(other) || overlaps?(other) end |
#does_not_overlap?(other) ⇒ Boolean
34 35 36 |
# File 'lib/availabiliter/time_slot.rb', line 34 def does_not_overlap?(other) starting_time > other.ending_time || ending_time < other.starting_time end |
#furthest(other) ⇒ Object
14 15 16 |
# File 'lib/availabiliter/time_slot.rb', line 14 def furthest(other) [self, other].max_by(&:ending_time) end |
#next_second ⇒ Object
22 23 24 |
# File 'lib/availabiliter/time_slot.rb', line 22 def next_second ending_time + 1 end |
#overlaps?(other) ⇒ Boolean
30 31 32 |
# File 'lib/availabiliter/time_slot.rb', line 30 def overlaps?(other) !does_not_overlap?(other) end |
#previous_second ⇒ Object
26 27 28 |
# File 'lib/availabiliter/time_slot.rb', line 26 def previous_second starting_time - 1 end |