Class: Respect::MultipleOfValidator

Inherits:
Validator
  • Object
show all
Defined in:
lib/respect/multiple_of_validator.rb

Instance Method Summary (collapse)

Methods inherited from Validator

constraint_name, #to_h

Constructor Details

- (MultipleOfValidator) initialize(multiplier)

A new instance of MultipleOfValidator



3
4
5
# File 'lib/respect/multiple_of_validator.rb', line 3

def initialize(multiplier)
  @validator = DivisibleByValidator.new(multiplier)
end

Instance Method Details

- (Object) validate(value)



7
8
9
10
11
12
13
14
# File 'lib/respect/multiple_of_validator.rb', line 7

def validate(value)
  begin
    @validator.validate(value)
  rescue ValidationError => e
    raise ValidationError,
          e.message.sub(/\bdivisible by\b/, "a multiple of")
  end
end