Class: ActiveRecordSurvey::Node::Answer::Scale
- Inherits:
-
ActiveRecordSurvey::Node::Answer
- Object
- ActiveRecord::Base
- ActiveRecordSurvey::Node
- ActiveRecordSurvey::Node::Answer
- ActiveRecordSurvey::Node::Answer::Scale
- Extended by:
- Answer::Chained::ClassMethods
- Includes:
- Answer::Chained::InstanceMethods
- Defined in:
- lib/active_record_survey/node/answer/scale.rb
Overview
Can hold a value on a scale (e.g. from 0-10)
Instance Method Summary collapse
-
#is_answered_for_instance?(instance) ⇒ Boolean
Scale answers are considered answered if they have a value of greater than “0”.
-
#validate_instance_node(instance_node) ⇒ Object
Accept integer, float, or empty values.
Methods inherited from ActiveRecordSurvey::Node::Answer
#build_link, #move_down, #move_up, #next_question, #question, #remove_link, #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?, #validate_parent_instance_node
Instance Method Details
#is_answered_for_instance?(instance) ⇒ Boolean
Scale answers are considered answered if they have a value of greater than “0”
15 16 17 18 19 20 21 22 |
# File 'lib/active_record_survey/node/answer/scale.rb', line 15 def is_answered_for_instance?(instance) if instance_node = self.instance_node_for_instance(instance) # Answered if not empty and > 0 !instance_node.value.to_s.empty? && instance_node.value.to_i >= 0 else false end end |
#validate_instance_node(instance_node) ⇒ Object
Accept integer, float, or empty values
8 9 10 11 12 |
# File 'lib/active_record_survey/node/answer/scale.rb', line 8 def validate_instance_node(instance_node) # super - all validations on this node pass super && (instance_node.value.to_s.empty? || !instance_node.value.to_s.match(/^(\d+(\.\d+)?)$/).nil?) end |