Class: Decidim::Forms::UserAnswersSerializer
- Inherits:
 - 
      Exporters::Serializer
      
        
- Object
 - Exporters::Serializer
 - Decidim::Forms::UserAnswersSerializer
 
 
- Includes:
 - TranslationsHelper
 
- Defined in:
 - lib/decidim/forms/user_answers_serializer.rb
 
Overview
This class serializes the answers given by a User for questionnaire so can be exported to CSV, JSON or other formats.
Instance Method Summary collapse
- 
  
    
      #initialize(answers)  ⇒ UserAnswersSerializer 
    
    
  
  
  
    constructor
  
  
  
  
  
  
  
    
Public: Initializes the serializer with a collection of Answers.
 - 
  
    
      #serialize  ⇒ Object 
    
    
  
  
  
  
  
  
  
  
  
    
Public: Exports a hash with the serialized data for the user answers.
 
Constructor Details
#initialize(answers) ⇒ UserAnswersSerializer
Public: Initializes the serializer with a collection of Answers.
      11 12 13  | 
    
      # File 'lib/decidim/forms/user_answers_serializer.rb', line 11 def initialize(answers) @answers = answers end  | 
  
Instance Method Details
#serialize ⇒ Object
Public: Exports a hash with the serialized data for the user answers.
      16 17 18 19 20 21 22 23 24 25  | 
    
      # File 'lib/decidim/forms/user_answers_serializer.rb', line 16 def serialize answers_hash = hash_for(@answers.first) answers_hash.merge!(questions_hash) @answers.each do |answer| answers_hash[translated_question_key(answer.question.position, answer.question.body)] = normalize_body(answer) end answers_hash end  |