class Mustermann::RegexpBased
Superclass for patterns that internally compile to a regular expression. @see Mustermann::Pattern @abstract
Attributes
@return [Regexp] regular expression equivalent to the pattern.
@return [Regexp] regular expression equivalent to the pattern.
Public Class Methods
Source
# File lib/mustermann/regexp_based.rb, line 17 def initialize(string, **options) super regexp = compile(**options) @peek_regexp = /\A#{regexp}/ @regexp = /\A#{regexp}\Z/ end
@param (see Mustermann::Pattern#initialize) @return (see Mustermann::Pattern#initialize) @see (see Mustermann::Pattern#initialize)
Calls superclass method
Mustermann::Pattern::new
Public Instance Methods
Source
# File lib/mustermann/regexp_based.rb, line 35 def peek_match(string) @peek_regexp.match(string) end
@param (see Mustermann::Pattern#peek_match) @return (see Mustermann::Pattern#peek_match) @see (see Mustermann::Pattern#peek_match)
Source
# File lib/mustermann/regexp_based.rb, line 27 def peek_size(string) return unless match = peek_match(string) match.to_s.size end
@param (see Mustermann::Pattern#peek_size) @return (see Mustermann::Pattern#peek_size) @see (see Mustermann::Pattern#peek_size)
Private Instance Methods
Source
# File lib/mustermann/regexp_based.rb, line 42 def compile(**options) raise NotImplementedError, 'subclass responsibility' end