Class: Mustermann::RegexpBased Abstract
- Extended by:
- Forwardable
- Defined in:
- lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/mustermann-3.0.0/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
CompileError, DEFAULT_TYPE, Error, ExpandError, ParseError
Instance Attribute Summary collapse
-
#regexp ⇒ Regexp
(also: #to_regexp)
readonly
Regular expression equivalent to the pattern.
Attributes inherited from 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
#+, #==, #===, #=~, #eql?, #expand, #hash, #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.
17 18 19 20 21 22 |
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/mustermann-3.0.0/lib/mustermann/regexp_based.rb', line 17 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.
11 12 13 |
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/mustermann-3.0.0/lib/mustermann/regexp_based.rb', line 11 def regexp @regexp end |
Instance Method Details
#peek_match(string) ⇒ MatchData, ...
Returns MatchData or similar object if the pattern matches.
35 36 37 |
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/mustermann-3.0.0/lib/mustermann/regexp_based.rb', line 35 def peek_match(string) @peek_regexp.match(string) end |
#peek_size(string) ⇒ Integer?
Returns the number of characters that match.
27 28 29 30 |
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/mustermann-3.0.0/lib/mustermann/regexp_based.rb', line 27 def peek_size(string) return unless match = peek_match(string) match.to_s.size end |