Sha256: 7ab15fe79de1702fb5115dede05018b768780c40c1923debefb6b7aeee4e3bbe

Contents?: true

Size: 593 Bytes

Versions: 4

Compression:

Stored size: 593 Bytes

Contents

module ActiveRecordSurvey
	# Boolean answers can have values 0|1
	class Node::Answer::Boolean < Node::Answer
		include Answer::Chained

		# Only boolean values
		def validate_instance_node(instance_node)
			# super - all validations on this node pass
			super &&
			!instance_node.value.to_s.match(/^[0|1]$/).nil?
		end

		# Boolean answers are considered answered if they have a value of "1"
		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
	end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
active_record_survey-0.1.28 lib/active_record_survey/node/answer/boolean.rb
active_record_survey-0.1.27 lib/active_record_survey/node/answer/boolean.rb
active_record_survey-0.1.26 lib/active_record_survey/node/answer/boolean.rb
active_record_survey-0.1.25 lib/active_record_survey/node/answer/boolean.rb