Class: Decidim::Meetings::Calendar::MeetingToEvent
- Inherits:
-
Object
- Object
- Decidim::Meetings::Calendar::MeetingToEvent
- Includes:
- ActionView::Helpers::SanitizeHelper
- Defined in:
- 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
-
#event ⇒ Object
Converts the given meeting to an ICalendar event object.
-
#initialize(meeting) ⇒ MeetingToEvent
constructor
Initializes the converter for the given meeting.
Constructor Details
#initialize(meeting) ⇒ MeetingToEvent
Initializes the converter for the given meeting.
meeting - the Meeting to convert
28 29 30 |
# File 'app/services/decidim/meetings/calendar/meeting_to_event.rb', line 28 def initialize(meeting) @meeting = meeting end |
Instance Method Details
#event ⇒ Object
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 '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 = description_with_link @event.location = meeting.address @event.geo = [meeting.latitude, meeting.longitude] @event.url = url_for(meeting) @event end |