Class: Qe::AnswerSheet

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
app/models/qe/answer_sheet.rb

Direct Known Subclasses

ReferenceSheet

Instance Method Summary collapse

Instance Method Details

#answers_by_questionObject

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_titleObject



53
54
55
# File 'app/models/qe/answer_sheet.rb', line 53

def collat_title() 
  "" 
end

#complete?Boolean

Returns:

  • (Boolean)


10
11
12
# File 'app/models/qe/answer_sheet.rb', line 10

def complete?
  !completed_at.nil?
end

#completely_filled_out?Boolean

Returns:

  • (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

Returns:

  • (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

#pagesObject



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_completeObject



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_sheetObject

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

Returns:

  • (Boolean)


36
37
38
# File 'app/models/qe/answer_sheet.rb', line 36

def reference?
  false
end