Class: Toys::Acceptor::Pattern
Overview
Defined in the toys-core gem
An acceptor that uses a regex to validate input. It also supports a custom conversion function that generates the final value from the match results.
Instance Attribute Summary
Attributes inherited from Base
Instance Method Summary collapse
-
#initialize(regex, converter = nil, type_desc: nil, well_known_spec: nil, &block) ⇒ Pattern
constructor
Create a pattern acceptor.
Methods inherited from Base
#convert, #match, #suggestions, #to_s
Constructor Details
#initialize(regex, converter = nil, type_desc: nil, well_known_spec: nil, &block) ⇒ Pattern
Create a pattern acceptor.
You must provide a regular expression (or any object that duck-types
Regexp#match
) as a validator.
You may also optionally provide a converter, either as a proc or a
block. A converter must take as its arguments the values in the
MatchData
returned from a successful regex match. That is, the first
argument is the original input string, and the remaining arguments are
the captures. The converter must return the final converted value.
If no converter is provided, no conversion is done and the input string
is returned.
215 216 217 |
# File 'core-docs/toys/acceptor.rb', line 215 def initialize(regex, converter = nil, type_desc: nil, well_known_spec: nil, &block) # Source available in the toys-core gem end |