Class: Rapidfire::QuestionGroupResults
- Inherits:
-
BaseService
- Object
- BaseService
- Rapidfire::QuestionGroupResults
- Defined in:
- app/services/rapidfire/question_group_results.rb
Instance Attribute Summary collapse
-
#question_group ⇒ Object
Returns the value of attribute question_group.
Instance Method Summary collapse
-
#extract ⇒ Object
extracts question along with results each entry will have the following: 1.
Methods inherited from BaseService
Constructor Details
This class inherits a constructor from Rapidfire::BaseService
Instance Attribute Details
#question_group ⇒ Object
Returns the value of attribute question_group.
3 4 5 |
# File 'app/services/rapidfire/question_group_results.rb', line 3 def question_group @question_group end |
Instance Method Details
#extract ⇒ Object
extracts question along with results each entry will have the following:
-
question type and question id
-
question text
-
if aggregatable, return each option with value
-
else return an array of all the answers given
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'app/services/rapidfire/question_group_results.rb', line 11 def extract @question_group.questions.collect do |question| results = case question when Rapidfire::Questions::Select, Rapidfire::Questions::Radio, Rapidfire::Questions::Checkbox answers = question.answers.map(&:answer_text).map { |text| text.split(',') }.flatten answers.inject(Hash.new(0)) { |total, e| total[e] += 1; total } when Rapidfire::Questions::Short, Rapidfire::Questions::Date, Rapidfire::Questions::Long, Rapidfire::Questions::Numeric question.answers.pluck(:answer_text) end QuestionResult.new(question: question, results: results) end end |