Class: Utils::Patterns::RegexpPattern

Inherits:
Pattern show all
Defined in:
lib/utils/patterns.rb

Overview

A regular expression pattern matcher that performs exact string matching with optional case sensitivity.

This class extends the base Pattern class to provide functionality for creating and using regular expression patterns. It compiles the provided pattern into a Regexp object that can be used for matching operations throughout the application. The pattern matching behavior is influenced by the case sensitivity configuration inherited from the parent class.

Examples:

regexp_pattern = RegexpPattern.new(pattern: 'foo', icase: true)
regexp_pattern.match('FOO') # => matches because case insensitive

Instance Attribute Summary

Attributes inherited from Pattern

#matcher

Instance Method Summary collapse

Methods inherited from Pattern

#method_missing

Constructor Details

#initialize(opts = {}) ⇒ Regexp

Initializes a regular expression pattern matcher with the specified options.

This method sets up a regular expression object based on the pattern string and case sensitivity configuration that was previously initialized in the parent class. It compiles the pattern into a Regexp object that can be used for matching operations throughout the pattern matching process.

Parameters:

  • opts (Hash) (defaults to: {})

    a hash containing the pattern configuration options

Options Hash (opts):

  • :cset (String)

    the character set to filter pattern characters against

  • :icase (TrueClass, FalseClass)

    whether the pattern matching should be case sensitive

  • :pattern (String)

    the pattern string to be used for matching



128
129
130
131
132
133
# File 'lib/utils/patterns.rb', line 128

def initialize(opts = {})
  super
  @matcher = Regexp.new(
    @pattern, @icase ? Regexp::IGNORECASE : 0
  )
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Utils::Patterns::Pattern