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