Sha256: 30a771280527f91b0bfb398df2460edf7e6780d2064562a327ef791592ee1858
Contents?: true
Size: 792 Bytes
Versions: 57
Compression:
Stored size: 792 Bytes
Contents
# frozen_string_literal: true module Decidim module Surveys # This class serializes the answers given by a User for survey so can be # exported to CSV, JSON or other formats. class SurveyUserAnswersSerializer < Decidim::Exporters::Serializer include Decidim::TranslationsHelper # Public: Initializes the serializer with a collection of SurveyAnswers. def initialize(survey_answers) @survey_answers = survey_answers end # Public: Exports a hash with the serialized data for the user answers. def serialize @survey_answers.each_with_index.inject({}) do |serialized, (answer, idx)| serialized.update("#{idx + 1}. #{translated_attribute(answer.question.body)}" => answer.body) end end end end end
Version data entries
57 entries across 57 versions & 2 rubygems