Class: Decidim::Forms::DataPortabilityUserAnswersSerializer

Inherits:
Exporters::Serializer show all
Includes:
TranslationsHelper
Defined in:
decidim-forms/lib/decidim/forms/data_portability_user_answers_serializer.rb

Instance Attribute Summary

Attributes inherited from Exporters::Serializer

#resource

Instance Method Summary collapse

Methods included from TranslationsHelper

empty_translatable, ensure_translatable, multi_translation, translated_in_current_locale?

Methods included from TranslatableAttributes

#default_locale?

Methods inherited from Exporters::Serializer

#event_name, #finalize, #initialize, #run

Constructor Details

This class inherits a constructor from Decidim::Exporters::Serializer

Instance Method Details

#serializeObject

Serializes an user answer for data portability


8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'decidim-forms/lib/decidim/forms/data_portability_user_answers_serializer.rb', line 8

def serialize
  {
    id: resource.id,
    user: {
      name: resource.user.name,
      email: resource.user.email
    },
    questionnaire: {
      id: resource.question.questionnaire.id,
      title: translated_attribute(resource.question.questionnaire.title),
      description: translated_attribute(resource.question.questionnaire.description),
      tos: translated_attribute(resource.question.questionnaire.tos)
    },
    question: {
      id: resource.question.id,
      body: translated_attribute(resource.question.body),
      description: translated_attribute(resource.question.description)
    },
    answer: normalize_body(resource)
  }
end