Class: CalendarAssistant::Scheduler

Inherits:
Object
  • Object
show all
Defined in:
lib/calendar_assistant/scheduler.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(calendar_assistant, event_repositories) ⇒ Scheduler

instance methods



23
24
25
26
# File 'lib/calendar_assistant/scheduler.rb', line 23

def initialize(calendar_assistant, event_repositories)
  @ca = calendar_assistant
  @ers = Array(event_repositories)
end

Instance Attribute Details

#caObject (readonly)

Returns the value of attribute ca.



3
4
5
# File 'lib/calendar_assistant/scheduler.rb', line 3

def ca
  @ca
end

#ersObject (readonly)

Returns the value of attribute ers.



3
4
5
# File 'lib/calendar_assistant/scheduler.rb', line 3

def ers
  @ers
end

Class Method Details

.select_busy_events(event_set) ⇒ Object

class methods



8
9
10
11
12
13
14
15
16
17
18
# File 'lib/calendar_assistant/scheduler.rb', line 8

def self.select_busy_events(event_set)
  dates_events = Hash.new
  event_set.events.each do |event|
    if event.private? || event.accepted? || event.self? || (event.all_day? && event.busy?)
      date = event.start_date
      dates_events[date] ||= []
      dates_events[date] << event
    end
  end
  event_set.new dates_events
end

Instance Method Details

#available_blocks(time_range, predicates: {}) ⇒ Object



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/calendar_assistant/scheduler.rb', line 28

def available_blocks(time_range, predicates: {})
  avail = nil
  ers.each do |er|
    event_set = er.find time_range, predicates: predicates # array
    event_set = Scheduler.select_busy_events event_set # hash
    event_set.ensure_keys time_range.first.to_date..time_range.last.to_date, only: true

    length = ChronicDuration.parse(ca.config.setting(Config::Keys::Settings::MEETING_LENGTH))
    ca.in_env do
      set_avail = event_set.available_blocks(length: length)
      avail = avail ? avail.intersection(set_avail, length: length) : set_avail
    end
  end
  avail
end