class Decidim::Votings::VotingSerializer
This class serializes a Voting so it can be exported to CSV, JSON or other formats.
Attributes
voting[R]
Public Class Methods
new(voting)
click to toggle source
Public: Initializes the serializer with a voting.
# File lib/decidim/votings/voting_serializer.rb, line 13 def initialize(voting) @voting = voting end
Public Instance Methods
serialize()
click to toggle source
Public: Exports a hash with the serialized data for this voting.
# 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
Private Instance Methods
translated_voting_type()
click to toggle source
# File lib/decidim/votings/voting_serializer.rb, line 40 def translated_voting_type translation_hash = {} voting.organization.available_locales.each do |locale| translation_hash[locale] = I18n.t(voting.voting_type, scope: "decidim.votings.admin.votings.form.voting_type") end translation_hash end
url()
click to toggle source
# File lib/decidim/votings/voting_serializer.rb, line 49 def url Decidim::Votings::Engine.routes.url_helpers.voting_url(host: voting.organization.host, slug: voting.slug) end