Class: Helena::Answer
Class Method Summary
collapse
Class Method Details
.answer_class_for(value) ⇒ Object
.build_generic(code, value, ip_address) ⇒ Object
13
14
15
16
|
# File 'app/models/helena/answer.rb', line 13
def self.build_generic(code, value, ip_address)
value = cast_value(value)
answer_class_for(value).new(code: code, value: value, ip_address: ip_address)
end
|
.cast_value(value) ⇒ Object
31
32
33
34
35
36
37
38
39
40
41
|
# File 'app/models/helena/answer.rb', line 31
def self.cast_value(value)
if value == 'true'
true
elsif value == 'false'
false
elsif integer?(value)
value.to_i
else
value.to_s
end
end
|
.integer?(str) ⇒ Boolean
43
44
45
46
47
|
# File 'app/models/helena/answer.rb', line 43
def self.integer?(str)
Integer(str)
rescue StandardError
false
end
|