Class: Decidim::Meetings::MeetingSerializer

Inherits:
Exporters::Serializer
  • Object
show all
Includes:
ApplicationHelper, ResourceHelper
Defined in:
lib/decidim/meetings/meeting_serializer.rb

Overview

This class serializes a Meeting so can be exported to CSV, JSON or other formats.

Instance Method Summary collapse

Constructor Details

#initialize(meeting) ⇒ MeetingSerializer

Public: Initializes the serializer with a meeting.



12
13
14
# File 'lib/decidim/meetings/meeting_serializer.rb', line 12

def initialize(meeting)
  @meeting = meeting
end

Instance Method Details

#serializeObject

Public: Exports a hash with the serialized data for this meeting.



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/decidim/meetings/meeting_serializer.rb', line 17

def serialize
  {
    id: meeting.id,
    category: {
      id: meeting.category.try(:id),
      name: meeting.category.try(:name)
    },
    scope: {
      id: meeting.scope.try(:id),
      name: meeting.scope.try(:name)
    },
    participatory_space: {
      id: meeting.participatory_space.id,
      url: Decidim::ResourceLocatorPresenter.new(meeting.participatory_space).url
    },
    component: { id: component.id },
    title: meeting.title,
    description: meeting.description,
    start_time: meeting.start_time,
    end_time: meeting.end_time,
    attendees: meeting.attendees_count.to_i,
    contributions: meeting.contributions_count.to_i,
    organizations: meeting.attending_organizations,
    address: meeting.address,
    location: meeting.location,
    reference: meeting.reference,
    comments: meeting.comments_count,
    attachments: meeting.attachments.size,
    followers: meeting.follows.size,
    url:,
    related_proposals:,
    related_results:,
    published: meeting.published_at.present?,
    withdrawn: meeting.withdrawn?,
    withdrawn_at: meeting.withdrawn_at
  }
end