Class: Decidim::Meetings::Calendar::MeetingToEvent

Inherits:
Object
  • Object
show all
Includes:
ActionView::Helpers::SanitizeHelper
Defined in:
decidim-meetings/app/services/decidim/meetings/calendar/meeting_to_event.rb

Overview

This class converts the given meeting to an ICalendar event, using the ‘icalendar` gem.

Examples:

meeting = Decidim::Meetings::Meeting.find(params[:id])
converter = MeetingToEvent.new(meeting)
converter.event # => #<Icalendar::Event ...>
converter.to_ical # => "BEGIN:VEVENT\n\r...END:VEVENT\n\r"

Note that this event will not be bound to any calendar. If you need to attach it to a calendar, you can do it like this:

calendar = Icalendar::Calendar.new
event = MeetingToEvent.new(meeting).event
calendar.add_event(event)

Instance Method Summary collapse

Constructor Details

#initialize(meeting) ⇒ MeetingToEvent

Initializes the converteer for the given meeting.

meeting - the Meeting to convert



28
29
30
# File 'decidim-meetings/app/services/decidim/meetings/calendar/meeting_to_event.rb', line 28

def initialize(meeting)
  @meeting = meeting
end

Instance Method Details

#eventObject

Converts the given meeting to an ICalendar event object

Returns an ICalendar::Event instance



35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'decidim-meetings/app/services/decidim/meetings/calendar/meeting_to_event.rb', line 35

def event
  return @event if @event

  @event = Icalendar::Event.new
  @event.dtstart = Icalendar::Values::DateTime.new(meeting.start_time.utc, "tzid" => "UTC")
  @event.dtend = Icalendar::Values::DateTime.new(meeting.end_time.utc, "tzid" => "UTC")
  @event.summary = present(meeting).title
  @event.description = strip_tags(CGI.unescapeHTML(present(meeting).description))
  @event.location = meeting.address
  @event.geo = [meeting.latitude, meeting.longitude]
  @event.url = url_for(meeting)

  @event
end