Class: Decidim::Surveys::SurveyUserAnswersSerializer
- Inherits:
-
Exporters::Serializer
- Object
- Exporters::Serializer
- Decidim::Surveys::SurveyUserAnswersSerializer
- Includes:
- TranslationsHelper
- Defined in:
- lib/decidim/surveys/survey_user_answers_serializer.rb
Overview
This class serializes the answers given by a User for survey so can be exported to CSV, JSON or other formats.
Instance Method Summary collapse
-
#initialize(survey_answers) ⇒ SurveyUserAnswersSerializer
constructor
Public: Initializes the serializer with a collection of SurveyAnswers.
-
#serialize ⇒ Object
Public: Exports a hash with the serialized data for the user answers.
Constructor Details
#initialize(survey_answers) ⇒ SurveyUserAnswersSerializer
Public: Initializes the serializer with a collection of SurveyAnswers.
11 12 13 |
# File 'lib/decidim/surveys/survey_user_answers_serializer.rb', line 11 def initialize(survey_answers) @survey_answers = survey_answers end |
Instance Method Details
#serialize ⇒ Object
Public: Exports a hash with the serialized data for the user answers.
16 17 18 19 20 |
# File 'lib/decidim/surveys/survey_user_answers_serializer.rb', line 16 def serialize @survey_answers.each_with_index.inject({}) do |serialized, (answer, idx)| serialized.update("#{idx + 1}. #{translated_attribute(answer.question.body)}" => normalize_body(answer)) end end |