Class: Decidim::Meetings::Calendar::BaseCalendar

Inherits:
Object
  • Object
show all
Defined in:
decidim-meetings/app/services/decidim/meetings/calendar/base_calendar.rb

Overview

This class serves as a base class to render calendars. Please, inherit from it and overwrite the `events` with whatever logic you need to do it. After that, modify the `Decidim::Meetings::Calendar.for` method to include your new class.

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(resource) ⇒ BaseCalendar

Initializes the class.

resource - a resource that has meetings.


24
25
26
# File 'decidim-meetings/app/services/decidim/meetings/calendar/base_calendar.rb', line 24

def initialize(resource)
  @resource = resource
end

Class Method Details

.for(resource) ⇒ Object

Convenience method to shorten the calls. Converts the resource meetings to the ICalendar format.

resource - a resource that has meetings.

Returns a String.


17
18
19
# File 'decidim-meetings/app/services/decidim/meetings/calendar/base_calendar.rb', line 17

def self.for(resource)
  new(resource).calendar
end

Instance Method Details

#calendarObject

Converts the resource meetings to the ICalendar format.

Returns a String.


31
32
33
34
35
36
37
38
39
40
41
42
# File 'decidim-meetings/app/services/decidim/meetings/calendar/base_calendar.rb', line 31

def calendar
  return if events.blank?

  <<~CALENDAR.gsub("\n\n", "\n")
    BEGIN:VCALENDAR\r
    VERSION:2.0\r
    PRODID:icalendar-ruby\r
    CALSCALE:GREGORIAN\r
    #{events}
    END:VCALENDAR\r
  CALENDAR
end

#eventsObject

Internal: this method is supposed to be overwritten by classes inheriting from this one. It should find the relevant meetings that will be exported, and convert them to ICalendar events. Please use the `MeetingToEvent` class to do so. Since this method returns a String, you can cache its contents. Check existing implementations for an example of how to achieve it.

Returns a String.


52
53
54
# File 'decidim-meetings/app/services/decidim/meetings/calendar/base_calendar.rb', line 52

def events
  raise "Please, overwrite this method. You can use the `MeetingToEvent` class to convert a meeting to the correct ICalendar format."
end