Class: Candl::EventLoaderModel

Inherits:
Object
  • Object
show all
Defined in:
lib/candl/event_loader_model.rb

Class Method Summary collapse

Class Method Details

.get_events(calendar_adress, from, to, view) ⇒ Object

load events prepared for agenda view



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/candl/event_loader_model.rb', line 9

def self.get_events(calendar_adress, from, to, view)
  begin
    events = parse_calendar(calendar_adress, from, to)
    initialization_successful = true
  rescue => exception
    logger.error "ERROR: #{exception}"
    initialization_successful = false
  end

  if view == :month
    sorted_events = (events).sort_by do |el|
      [el.dtstart, el.summary]
    end
  elsif view == :agenda
    spreaded_events = spread_multiday_events(events, from, to)

    sorted_events = (events + spreaded_events.to_a).sort_by do |el|
      [el.dtstart, el.summary]
    end
  else
    raise `Unknown view type: #{view}`
  end

  { events: sorted_events, success: initialization_successful }
end