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, filters = nil) ⇒ BaseCalendar

Initializes the class.

resource - a resource that has meetings.



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

def initialize(resource, filters = nil)
  @resource = resource
  @filters = filters
end

Class Method Details

.for(resource, filters = nil) ⇒ 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, filters = nil)
  new(resource, filters).calendar
end

Instance Method Details

#calendarObject

Converts the resource meetings to the ICalendar format.

Returns a String.



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

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.



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

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