Module: Utils::Patterns
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.
114 115 116 117 118 119 120 121 122 123 |
# File 'lib/utils/patterns.rb', line 114 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 |