Class: Decidim::Votings::VotingSerializer

Inherits:
Exporters::Serializer
  • Object
show all
Includes:
ApplicationHelper, ResourceHelper, TranslationsHelper
Defined in:
lib/decidim/votings/voting_serializer.rb

Overview

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

Instance Method Summary collapse

Constructor Details

#initialize(voting) ⇒ VotingSerializer

Public: Initializes the serializer with a voting.



13
14
15
# File 'lib/decidim/votings/voting_serializer.rb', line 13

def initialize(voting)
  @voting = voting
end

Instance Method Details

#serializeObject

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



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/decidim/votings/voting_serializer.rb', line 18

def serialize
  {
    participatory_space_id: voting.id,
    url: url,
    title: voting.title,
    description: voting.description,
    start_time: voting.start_time.to_s(:db),
    end_time: voting.end_time.to_s(:db),
    voting_type: translated_voting_type,
    scope: {
      id: voting.scope.try(:id),
      name: voting.scope.try(:name)
    },
    banner_image_url: Decidim::Votings::VotingPresenter.new(voting).banner_image_url,
    introductory_image_url: Decidim::Votings::VotingPresenter.new(voting).introductory_image_url
  }
end