Class: Decidim::Meetings::QuestionnaireUserAnswers
- Inherits:
-
Query
- Object
- Query
- Decidim::Meetings::QuestionnaireUserAnswers
- Defined in:
- app/queries/decidim/meetings/questionnaire_user_answers.rb
Overview
A class used to collect user answers for a questionnaire
Class Method Summary collapse
-
.for(questionnaire) ⇒ Object
Syntactic sugar to initialize the class and return the queried objects.
Instance Method Summary collapse
-
#initialize(questionnaire) ⇒ QuestionnaireUserAnswers
constructor
Initializes the class.
-
#query ⇒ Object
Finds and group answers by user for each questionnaire’s question.
Constructor Details
#initialize(questionnaire) ⇒ QuestionnaireUserAnswers
Initializes the class.
questionnaire = a Questionnaire object
17 18 19 |
# File 'app/queries/decidim/meetings/questionnaire_user_answers.rb', line 17 def initialize(questionnaire) @questionnaire = questionnaire end |
Class Method Details
.for(questionnaire) ⇒ Object
Syntactic sugar to initialize the class and return the queried objects.
questionnaire - a Questionnaire object
10 11 12 |
# File 'app/queries/decidim/meetings/questionnaire_user_answers.rb', line 10 def self.for(questionnaire) new(questionnaire).query end |
Instance Method Details
#query ⇒ Object
Finds and group answers by user for each questionnaire’s question.
22 23 24 25 26 |
# File 'app/queries/decidim/meetings/questionnaire_user_answers.rb', line 22 def query answers = Answer.joins(:question).where(questionnaire: @questionnaire) answers.sort_by { |answer| answer.question.position }.group_by(&:user).values end |