Class: Veto::LessThanOrEqualToValidator

Inherits:
AttributeValidator show all
Defined in:
lib/veto/validators/less_than_or_equal_to_validator.rb

Instance Method Summary collapse

Methods inherited from AttributeValidator

#execute, #initialize

Methods inherited from AbstractValidator

#execute

Constructor Details

This class inherits a constructor from Veto::AttributeValidator

Instance Method Details

#validate(entity, attribute, value, errors, options = {}) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/veto/validators/less_than_or_equal_to_validator.rb', line 5

def validate entity, attribute, value, errors, options={}
  boundary = options.fetch(:with)    
  message = options.fetch(:message, :less_than_or_equal_to)
  on = options.fetch(:on, attribute)
  
  begin
    v = Kernel.Float(value.to_s)
    nil
  rescue
    return errors.add(on, message, boundary)
  end

  unless v <= boundary
    errors.add(on, message, boundary)
  end
end