module Utils::Patterns
def choose(argument, pattern_opts, default: ?f)
-
(ArgumentError)
- if the pattern option is not provided to the pattern matcher constructor -
(ArgumentError)
- if the argument does not match 'r' or 'f' patterns and is not nil
Returns:
-
(Utils::Patterns::Pattern)
- a new instance of either RegexpPattern or FuzzyPattern
Parameters:
-
default
(String
) -- the default pattern type to use when argument is nil or empty -
pattern_opts
(Hash
) -- the options to be passed to the pattern matcher constructor -
argument
(String
) -- the argument string that determines the pattern type
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