Class: HashValidator::Validator::RegexpValidator

Inherits:
Base
  • Object
show all
Defined in:
lib/hash_validator/validators/regex_validator.rb

Instance Attribute Summary

Attributes inherited from Base

#name

Instance Method Summary collapse

Methods inherited from Base

#validate

Constructor Details

#initializeRegexpValidator

Returns a new instance of RegexpValidator.



2
3
4
# File 'lib/hash_validator/validators/regex_validator.rb', line 2

def initialize
  super('_regex')  # The name of the validator, underscored as it won't usually be directly invoked (invoked through use of validator)
end

Instance Method Details

#error_messageObject



10
11
12
# File 'lib/hash_validator/validators/regex_validator.rb', line 10

def error_message
  'does not match regular expression'
end

#should_validate?(rhs) ⇒ Boolean

Returns:

  • (Boolean)


6
7
8
# File 'lib/hash_validator/validators/regex_validator.rb', line 6

def should_validate?(rhs)
  rhs.is_a?(Regexp)
end

#valid?(value, regexp) ⇒ Boolean

Returns:

  • (Boolean)


14
15
16
# File 'lib/hash_validator/validators/regex_validator.rb', line 14

def valid?(value, regexp)
  regexp.match(value.to_s)
end