Module: Utils::Patterns
Overview
A module that provides pattern matching functionality for file searching and text processing.
It includes classes for different types of pattern matching including fuzzy matching and regular expression matching.
Defined Under Namespace
Classes: FuzzyPattern, Pattern, RegexpPattern
Instance Method Summary collapse
-
#choose(argument, pattern_opts, default: ?f) ⇒ Utils::Patterns::Pattern
Chooses and initializes a pattern matcher based on the provided argument and options.
Instance Method Details
#choose(argument, pattern_opts, default: ?f) ⇒ Utils::Patterns::Pattern
Chooses and initializes a pattern matcher based on the provided argument and options.
This method selects between a regular expression pattern matcher and a fuzzy pattern matcher depending on the value of the argument parameter and the default configuration. It validates that the argument is either ‘r’ (regexp) or ‘f’ (fuzzy) and raises an error if an invalid value is provided.
153 154 155 156 157 158 159 160 161 162 |
# File 'lib/utils/patterns.rb', line 153 def choose(argument, pattern_opts, default: ?f) case argument when /^r/, (default == ?r ? nil : :not) RegexpPattern.new(pattern_opts) when /^f/, (default == ?f ? nil : :not) FuzzyPattern.new(pattern_opts) else raise ArgumentError, 'argument -p has to be f=fuzzy or r=regexp' end end |