Sha256: 39b49f63b04d870683fda6b5e09c28f9ebb4bf2c826c4cf50b303f2215649eb4

Contents?: true

Size: 649 Bytes

Versions: 20

Compression:

Stored size: 649 Bytes

Contents

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

		# 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

20 entries across 20 versions & 1 rubygems

Version Path
active_record_survey-0.1.49 lib/active_record_survey/node/answer/boolean.rb
active_record_survey-0.1.48 lib/active_record_survey/node/answer/boolean.rb
active_record_survey-0.1.47 lib/active_record_survey/node/answer/boolean.rb
active_record_survey-0.1.46 lib/active_record_survey/node/answer/boolean.rb
active_record_survey-0.1.45 lib/active_record_survey/node/answer/boolean.rb
active_record_survey-0.1.44 lib/active_record_survey/node/answer/boolean.rb
active_record_survey-0.1.43 lib/active_record_survey/node/answer/boolean.rb
active_record_survey-0.1.42 lib/active_record_survey/node/answer/boolean.rb
active_record_survey-0.1.41 lib/active_record_survey/node/answer/boolean.rb
active_record_survey-0.1.40 lib/active_record_survey/node/answer/boolean.rb
active_record_survey-0.1.39 lib/active_record_survey/node/answer/boolean.rb
active_record_survey-0.1.38 lib/active_record_survey/node/answer/boolean.rb
active_record_survey-0.1.37 lib/active_record_survey/node/answer/boolean.rb
active_record_survey-0.1.36 lib/active_record_survey/node/answer/boolean.rb
active_record_survey-0.1.35 lib/active_record_survey/node/answer/boolean.rb
active_record_survey-0.1.34 lib/active_record_survey/node/answer/boolean.rb
active_record_survey-0.1.32 lib/active_record_survey/node/answer/boolean.rb
active_record_survey-0.1.31 lib/active_record_survey/node/answer/boolean.rb
active_record_survey-0.1.30 lib/active_record_survey/node/answer/boolean.rb
active_record_survey-0.1.29 lib/active_record_survey/node/answer/boolean.rb