Class: Availabiliter::TimeSlotCollection

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/availabiliter/time_slot_collection.rb

Overview

A time slot collection is a sorted collection of time slots with a start and an end boundary

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(time_slots:, minimum_availability_start:, maximum_availability_end:) ⇒ TimeSlotCollection

Returns a new instance of TimeSlotCollection.



10
11
12
13
14
# File 'lib/availabiliter/time_slot_collection.rb', line 10

def initialize(time_slots:, minimum_availability_start:, maximum_availability_end:)
  @minimum_availability_start = minimum_availability_start
  @maximum_availability_end = maximum_availability_end
  @collection = build_collection(time_slots)
end

Instance Attribute Details

#collectionObject (readonly)

Returns the value of attribute collection.



8
9
10
# File 'lib/availabiliter/time_slot_collection.rb', line 8

def collection
  @collection
end

Instance Method Details

#availabilitiesObject



16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/availabiliter/time_slot_collection.rb', line 16

def availabilities
  furthest_time_slot = start_boundary

  filter_map.with_index do |time_slot, index|
    next_time_slot = collection[index + 1]
    furthest_time_slot = time_slot.furthest(furthest_time_slot)

    next if index == last_time_slot_index
    next if furthest_time_slot.dependent?(next_time_slot)

    [furthest_time_slot.next_second, next_time_slot.previous_second]
  end
end