Class: FormatEventsIcal

Inherits:
Object
  • Object
show all
Includes:
Interpipe::Interactor, RolePlaying::Context
Defined in:
app/interactors/format_events_ical.rb

Overview

Converts Event's collection to an ICalendar.

Instance Method Summary collapse

Methods included from Interpipe::Interactor

included, #initialize

Instance Method Details

#icalObject Also known as: to_ical


40
41
42
# File 'app/interactors/format_events_ical.rb', line 40

def ical
  @calendar.to_ical
end

#perform(events: []) ⇒ String

Adds events to an ICalendar and convert it to a text representation.

Returns:

  • (String)

    ICalendar as a string.


23
24
25
26
27
28
29
# File 'app/interactors/format_events_ical.rb', line 23

def perform(events: [])
  @events = events.eager(:parallel, :course, :room).all

  @events.each do |e|
    @calendar.add_event IcalEvent(e).to_ical
  end
end

#resultsObject


36
37
38
# File 'app/interactors/format_events_ical.rb', line 36

def results
  {ical: ical}
end

#setupObject


15
16
17
18
# File 'app/interactors/format_events_ical.rb', line 15

def setup
  @calendar = Icalendar::Calendar.new
  @calendar.add_timezone timezone(Config.tz)
end

#timezone(tzid) ⇒ Object


31
32
33
34
# File 'app/interactors/format_events_ical.rb', line 31

def timezone(tzid)
  tz = TZInfo::Timezone.get(tzid)
  tz.ical_timezone(DateTime.new 2014) # XXX it needs _some_ date; maybe current year should be used instead?
end