Class: Decidim::Proposals::ProposalSerializer

Inherits:
Exporters::Serializer
  • Object
show all
Includes:
ResourceHelper
Defined in:
lib/decidim/proposals/proposal_serializer.rb

Overview

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

Instance Method Summary collapse

Constructor Details

#initialize(proposal) ⇒ ProposalSerializer

Public: Initializes the serializer with a proposal.



11
12
13
# File 'lib/decidim/proposals/proposal_serializer.rb', line 11

def initialize(proposal)
  @proposal = proposal
end

Instance Method Details

#serializeObject

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



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/decidim/proposals/proposal_serializer.rb', line 16

def serialize
  {
    id: @proposal.id,
    category: {
      id: @proposal.category.try(:id),
      name: @proposal.category.try(:name)
    },
    scope: {
      id: @proposal.scope.try(:id),
      name: @proposal.scope.try(:name)
    },
    title: @proposal.title,
    body: @proposal.body,
    votes: @proposal.proposal_votes_count,
    comments: @proposal.comments.count,
    created_at: @proposal.created_at,
    url: url,
    component: { id: component.id },
    meeting_urls: meetings
  }
end