Class: Owasp::Esapi::Validator::GenericValidator

Inherits:
Object
  • Object
show all
Defined in:
lib/validator/generic_validator.rb

Direct Known Subclasses

Email, Zipcode

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(matcher) ⇒ GenericValidator

Creates a new generic validator.

Parameters:

  • matcher (String)

    the regular expression to be matched from this validator



11
12
13
# File 'lib/validator/generic_validator.rb', line 11

def initialize(matcher)
  @matcher = matcher
end

Instance Attribute Details

#matcherObject

Returns the value of attribute matcher.



7
8
9
# File 'lib/validator/generic_validator.rb', line 7

def matcher
  @matcher
end

Instance Method Details

#valid?(string) ⇒ Boolean

Validate a string against the matcher

Parameters:

  • string (String)

    the string that need to be validated

Returns:

  • (Boolean)

    true if the string matches the regular expression, false otherwise



18
19
20
21
22
# File 'lib/validator/generic_validator.rb', line 18

def valid?(string)
  r = Regexp.new(@matcher)
  
  !(string =~ r).nil?
end