Class: ActiveRecordSurvey::Node::Answer::Boolean
- Inherits:
-
ActiveRecordSurvey::Node::Answer
- Object
- ActiveRecord::Base
- ActiveRecordSurvey::Node
- ActiveRecordSurvey::Node::Answer
- ActiveRecordSurvey::Node::Answer::Boolean
- Extended by:
- Answer::Chained::ClassMethods
- Includes:
- Answer::Chained::InstanceMethods
- Defined in:
- lib/active_record_survey/node/answer/boolean.rb
Overview
Boolean answers can have values 0|1
Instance Method Summary collapse
-
#is_answered_for_instance?(instance) ⇒ Boolean
Boolean answers are considered answered if they have a value of “1”.
-
#validate_instance_node(instance_node) ⇒ Object
Only boolean values.
Methods inherited from ActiveRecordSurvey::Node::Answer
#build_link, #move_down, #move_up, #next_question, #question, #sibling_index, #sibling_index=, #validate_node
Methods inherited from ActiveRecordSurvey::Node
#answers, #build_link, #has_instance_node_for_instance?, #instance_node_for_instance, #instance_node_path_to_root?, #remove_link, #validate_parent_instance_node
Instance Method Details
#is_answered_for_instance?(instance) ⇒ Boolean
Boolean answers are considered answered if they have a value of “1”
15 16 17 18 19 20 |
# File 'lib/active_record_survey/node/answer/boolean.rb', line 15 def is_answered_for_instance?(instance) if instance_node = self.instance_node_for_instance(instance) # Instance node is answered "1" (instance_node.value.to_i === 1) end end |
#validate_instance_node(instance_node) ⇒ Object
Only boolean values
8 9 10 11 12 |
# File 'lib/active_record_survey/node/answer/boolean.rb', line 8 def validate_instance_node(instance_node) # super - all validations on this node pass super && !instance_node.value.to_s.match(/^[0|1]$/).nil? end |