Class: Mustermann::RegexpBased Abstract
- Extended by:
- Forwardable
- Defined in:
- lib/mustermann/regexp_based.rb
Overview
This class is abstract.
Superclass for patterns that internally compile to a regular expression.
Direct Known Subclasses
Constant Summary
Constants included from Mustermann
Instance Attribute Summary collapse
-
#regexp ⇒ Regexp
(also: #to_regexp)
readonly
Regular expression equivalent to the pattern.
Instance Method Summary collapse
-
#initialize(string, **options) ⇒ Pattern
constructor
A new instance of Pattern.
-
#peek_match(string) ⇒ MatchData, ...
MatchData or similar object if the pattern matches.
-
#peek_size(string) ⇒ Integer?
The number of characters that match.
Methods inherited from Pattern
#===, #=~, #expand, #match, #named_captures, #names, new, #params, #peek, #peek_params, supported?, supported_options, #to_proc, #to_s, #to_templates, #|
Methods included from Mustermann
Constructor Details
#initialize(string, **options) ⇒ Pattern
Returns a new instance of Pattern.
16 17 18 19 20 21 |
# File 'lib/mustermann/regexp_based.rb', line 16 def initialize(string, **) super regexp = compile(**) @peek_regexp = /\A(#{regexp})/ @regexp = /\A#{regexp}\Z/ end |
Instance Attribute Details
#regexp ⇒ Regexp (readonly) Also known as: to_regexp
Returns regular expression equivalent to the pattern.
10 11 12 |
# File 'lib/mustermann/regexp_based.rb', line 10 def regexp @regexp end |
Instance Method Details
#peek_match(string) ⇒ MatchData, ...
Returns MatchData or similar object if the pattern matches.
34 35 36 |
# File 'lib/mustermann/regexp_based.rb', line 34 def peek_match(string) @peek_regexp.match(string) end |
#peek_size(string) ⇒ Integer?
Returns the number of characters that match.
26 27 28 29 |
# File 'lib/mustermann/regexp_based.rb', line 26 def peek_size(string) return unless match = peek_match(string) match.to_s.size end |