Class: Ronin::Core::Params::Types::Regexp
- Defined in:
- lib/ronin/core/params/types/regexp.rb
Overview
Represents a Regexp type.
Instance Method Summary collapse
-
#coerce(value) ⇒ Regexp
private
Parses the String value.
Instance Method Details
#coerce(value) ⇒ Regexp
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Parses the String value.
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/ronin/core/params/types/regexp.rb', line 45 def coerce(value) case value when ::Regexp then value when ::String unless (value.start_with?('/') && value.end_with?('/')) raise(ValidationError,"value must be of the format '/.../' (#{value.inspect})") end begin ::Regexp.new(value[1..-2]) rescue RegexpError raise(ValidationError,"value is not a valid Regexp (#{value.inspect})") end else raise(ValidationError,"value must be either a String or a Regexp (#{value.inspect})") end end |