Class: Response
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Response
show all
- Includes:
- ActionView::Helpers::SanitizeHelper
- Defined in:
- app/models/response.rb
Defined Under Namespace
Classes: InvalidResponseClass
Instance Method Summary
collapse
Instance Method Details
#correct? ⇒ Boolean
28
29
30
|
# File 'app/models/response.rb', line 28
def correct?
question.correct_answer_id.nil? or self.answer.response_class != "answer" or (question.correct_answer_id.to_i == answer_id.to_i)
end
|
#q_and_a_codes ⇒ Object
Return an individual response’s question and answer coded for Home Exposure questionnaire.
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
|
# File 'app/models/response.rb', line 49
def q_and_a_codes
q_code = self.question.data_export_identifier
unless %w( answer string integer float
text datetime
).include?(self.answer.response_class)
raise InvalidResponseClass
end
a_code = if self.answer.response_class == "answer"
self.answer.data_export_identifier
else
self.send("#{self.answer.response_class}_value")
end
[ q_code, a_code ]
end
|
#q_and_a_codes_and_text ⇒ Object
Also known as:
codes_and_text
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
|
# File 'app/models/response.rb', line 66
def q_and_a_codes_and_text
q_code = self.question.data_export_identifier
unless %w( answer string integer float
text datetime
).include?(self.answer.response_class)
raise InvalidResponseClass
end
a_code = if self.answer.response_class == "answer"
self.answer.data_export_identifier
else
self.send("#{self.answer.response_class}_value")
end
a_text = if self.answer.response_class == "answer"
self.answer.text
else
self.send("#{self.answer.response_class}_value")
end
q_text = self.question.text
{ q_code => { :a_code => a_code, :a_text => a_text, :q_text => q_text }}
end
|
#selected ⇒ Object
Also known as:
selected?
18
19
20
|
# File 'app/models/response.rb', line 18
def selected
!self.new_record?
end
|
#selected=(value) ⇒ Object
24
25
26
|
# File 'app/models/response.rb', line 24
def selected=(value)
true
end
|
#to_s ⇒ Object
used in dependency_explanation_helper
32
33
34
35
36
37
38
|
# File 'app/models/response.rb', line 32
def to_s if self.answer.response_class == "answer" and self.answer_id
return self.answer.text
else
return "#{(self.string_value || self.text_value || self.integer_value || self.float_value || nil).to_s}"
end
end
|