Class: Formidable::Validations::ValidateLength

Inherits:
Validation
  • Object
show all
Defined in:
lib/formidable/validations/length.rb

Instance Attribute Summary collapse

Attributes inherited from Validation

#element

Instance Method Summary collapse

Methods inherited from Validation

register

Constructor Details

#initialize(element, length) ⇒ ValidateLength

Returns a new instance of ValidateLength.



12
13
14
15
# File 'lib/formidable/validations/length.rb', line 12

def initialize(element, length)
  super(element)
  @length = length
end

Instance Attribute Details

#lengthObject (readonly)

Returns the value of attribute length.



11
12
13
# File 'lib/formidable/validations/length.rb', line 11

def length
  @length
end

Instance Method Details

#messageObject

TODO: user can set message



21
22
23
24
25
26
27
# File 'lib/formidable/validations/length.rb', line 21

def message # TODO: user can set message
  if length.respond_to?(:first)
    message_for_range
  else
    message_for_integer
  end
end

#valid?Boolean

Returns:

  • (Boolean)


17
18
19
# File 'lib/formidable/validations/length.rb', line 17

def valid?
  length === element.length
end