Class: Qe::AnswerSheet
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Qe::AnswerSheet
- Defined in:
- app/models/qe/answer_sheet.rb
Direct Known Subclasses
Instance Method Summary collapse
-
#answers_by_question ⇒ Object
answers for this sheet, grouped by question id.
- #collat_title ⇒ Object
- #complete? ⇒ Boolean
- #completely_filled_out? ⇒ Boolean
- #has_answer_for?(question_id) ⇒ Boolean
- #pages ⇒ Object
- #percent_complete ⇒ Object
-
#question_sheet ⇒ Object
Convenience method if there is only one question sheet in your system.
- #reference? ⇒ Boolean
Instance Method Details
#answers_by_question ⇒ Object
answers for this sheet, grouped by question id
15 16 17 |
# File 'app/models/qe/answer_sheet.rb', line 15 def answers_by_question @answers_by_question ||= self.answers.find(:all).group_by { |answer| answer.question_id } end |
#collat_title ⇒ Object
53 54 55 |
# File 'app/models/qe/answer_sheet.rb', line 53 def collat_title() "" end |
#complete? ⇒ Boolean
10 11 12 |
# File 'app/models/qe/answer_sheet.rb', line 10 def complete? !completed_at.nil? end |
#completely_filled_out? ⇒ Boolean
28 29 30 |
# File 'app/models/qe/answer_sheet.rb', line 28 def completely_filled_out? pages.all? {|p| p.complete?(self)} end |
#has_answer_for?(question_id) ⇒ Boolean
32 33 34 |
# File 'app/models/qe/answer_sheet.rb', line 32 def has_answer_for?(question_id) !answers_by_question[question_id].nil? end |
#pages ⇒ Object
24 25 26 |
# File 'app/models/qe/answer_sheet.rb', line 24 def pages Page.where(:question_sheet_id => question_sheets.collect(&:id)) end |
#percent_complete ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'app/models/qe/answer_sheet.rb', line 40 def percent_complete num_questions = 0 question_sheets.each { |qs| num_questions += qs.questions.length } return 0 if num_questions == 0 num_answers = answers.where("value IS NOT NULL && value != ''").select("DISTINCT question_id").count if [ [ (num_answers.to_f / num_questions.to_f * 100.0).to_i, 100 ].min, 0 ].max == 100 && !complete? return 99 else return [ [ (num_answers.to_f / num_questions.to_f * 100.0).to_i, 100 ].min, 0 ].max end end |
#question_sheet ⇒ Object
Convenience method if there is only one question sheet in your system
20 21 22 |
# File 'app/models/qe/answer_sheet.rb', line 20 def question_sheet question_sheets.first end |
#reference? ⇒ Boolean
36 37 38 |
# File 'app/models/qe/answer_sheet.rb', line 36 def reference? false end |