class Mustermann::Regular
Regexp pattern implementation.
@example
Mustermann.new('/.*', type: :regexp) === '/bar' # => true
@see Mustermann::Pattern @see file:README.md#simple Syntax description in the README
Public Class Methods
new(string, check_anchors: true, **options)
click to toggle source
@param (see Mustermann::Pattern#initialize) @return (see Mustermann::Pattern#initialize) @see (see Mustermann::Pattern#initialize)
Calls superclass method
Mustermann::RegexpBased.new
# File lib/mustermann/regular.rb, line 21 def initialize(string, check_anchors: true, **options) string = $1 if string.to_s =~ /\A\(\?\-mix\:(.*)\)\Z/ && string.inspect == "/#$1/" @check_anchors = check_anchors super(string, **options) end
Private Instance Methods
check_anchors(scanner)
click to toggle source
# File lib/mustermann/regular.rb, line 36 def check_anchors(scanner) return scanner.scan_until(/\]/) if scanner.scan(/\[/) return scanner.scan(/\?./) unless illegal = scanner.scan(/\[AzZ]|[\^\$]/) raise CompileError, "regular expression should not contain %s: %p" % [illegal.to_s, @string] end
compile(**options)
click to toggle source
# File lib/mustermann/regular.rb, line 27 def compile(**options) if @check_anchors scanner = ::StringScanner.new(@string) check_anchors(scanner) until scanner.eos? end /#{@string}/ end