Class: ActiveRecordSurvey::NodeValidation::MaximumLength

Inherits:
ActiveRecordSurvey::NodeValidation show all
Defined in:
lib/active_record_survey/node_validation/maximum_length.rb

Overview

Ensure the instance_node has a length less than the maximum

Instance Method Summary collapse

Methods inherited from ActiveRecordSurvey::NodeValidation

#validate_node

Instance Method Details

#validate_instance_node(instance_node, answer_node = nil) ⇒ Object

Validate the instance_node value



5
6
7
8
9
10
11
# File 'lib/active_record_survey/node_validation/maximum_length.rb', line 5

def validate_instance_node(instance_node, answer_node = nil)
	is_valid = (self.value.to_i >= instance_node.value.to_s.length.to_i)

	instance_node.errors[:base] << { :nodes => { answer_node.id => ["MAXIMUM_LENGTH"] } } if !is_valid

	is_valid
end