Class: FlycalCli::SlotFinder
- Inherits:
-
Object
- Object
- FlycalCli::SlotFinder
- Defined in:
- lib/flycal_cli/slot_finder.rb
Constant Summary collapse
- DEFAULT_HOURS =
[[9, 0, 18, 0]].freeze
- DEFAULT_DAYS =
[1, 2, 3, 4, 5].freeze
- STEP_SECONDS =
900
Instance Method Summary collapse
-
#initialize(events:, time_min:, time_max:, slot_duration_seconds:, hours: DEFAULT_HOURS, days: DEFAULT_DAYS, free_before_seconds: 0, free_after_seconds: 0) ⇒ SlotFinder
constructor
A new instance of SlotFinder.
- #slots_by_day ⇒ Object
Constructor Details
#initialize(events:, time_min:, time_max:, slot_duration_seconds:, hours: DEFAULT_HOURS, days: DEFAULT_DAYS, free_before_seconds: 0, free_after_seconds: 0) ⇒ SlotFinder
Returns a new instance of SlotFinder.
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/flycal_cli/slot_finder.rb', line 9 def initialize( events:, time_min:, time_max:, slot_duration_seconds:, hours: DEFAULT_HOURS, days: DEFAULT_DAYS, free_before_seconds: 0, free_after_seconds: 0 ) @events = events @time_min = time_min @time_max = time_max @slot_duration_seconds = slot_duration_seconds @hours = hours @days = Array(days).map(&:to_i) @free_before_seconds = free_before_seconds @free_after_seconds = free_after_seconds end |
Instance Method Details
#slots_by_day ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/flycal_cli/slot_finder.rb', line 29 def slots_by_day result = {} each_template_day do |date| slots = [] day_intervals(date).each do |day_start, day_end| next if day_end <= day_start busy = busy_intervals_for(date, day_start, day_end) gaps = free_gaps(day_start, day_end, busy) gaps.each do |gap_start, gap_end| slots.concat(slots_in_gap(gap_start, gap_end)) end end result[date] = slots unless slots.empty? end result end |