Class: Decidim::ParticipatoryDocuments::SuggestionSerializer

Inherits:
Exporters::Serializer
  • Object
show all
Includes:
ActionView::Helpers::TextHelper, ApplicationHelper, Admin::SuggestionHelper, TranslationsHelper
Defined in:
app/serializers/decidim/participatory_documents/suggestion_serializer.rb

Overview

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

Direct Known Subclasses

MySuggestionSerializer

Instance Method Summary collapse

Methods included from Admin::SuggestionHelper

#bulk_valuators_select, #humanize_suggestion_state, #icon_with_link_to_suggestion, #suggestion_content

Constructor Details

#initialize(suggestion) ⇒ SuggestionSerializer

Public: Initializes the serializer with a suggestion.



14
15
16
# File 'app/serializers/decidim/participatory_documents/suggestion_serializer.rb', line 14

def initialize(suggestion)
  @suggestion = suggestion
end

Instance Method Details

#serializeObject

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



19
20
21
22
23
24
25
26
27
28
29
30
# File 'app/serializers/decidim/participatory_documents/suggestion_serializer.rb', line 19

def serialize
  {
    id: suggestion.id,
    body: suggestion_body(suggestion),
    author: suggestion.try(:normalized_author).try(:name),
    state: humanize_suggestion_state(suggestion.state),
    answer: answer_text(suggestion),
    section: section(suggestion),
    valuators: suggestion.valuation_assignments.map(&:valuator).map(&:name).join(", "),
    submitted_on: (suggestion)
  }
end