Class: Utils::Patterns::FuzzyPattern
- Defined in:
- lib/utils/patterns.rb
Instance Attribute Summary
Attributes inherited from Pattern
Instance Method Summary collapse
-
#initialize(opts = {}) ⇒ FuzzyPattern
constructor
Initializes a fuzzy pattern matcher by processing the pattern string and compiling it into a regular expression.
Methods inherited from Pattern
Constructor Details
#initialize(opts = {}) ⇒ FuzzyPattern
Initializes a fuzzy pattern matcher by processing the pattern string and compiling it into a regular expression.
This method takes the configured pattern string and converts it into a regular expression that can match strings in a fuzzy manner, allowing for partial matches while preserving the order of characters. It handles case sensitivity based on the configuration.
62 63 64 65 66 67 68 69 70 |
# File 'lib/utils/patterns.rb', line 62 def initialize(opts = {}) super r = @pattern.split(//).grep(/[[:print:]]/).map { |x| "(#{Regexp.quote(x)})" } * '.*?' @matcher = Regexp.new( "\\A(?:.*/.*?#{r}|.*#{r})", @icase ? Regexp::IGNORECASE : 0 ) end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class Utils::Patterns::Pattern