Module: Utils::Patterns

Included in:
Finder, Grepper
Defined in:
lib/utils/patterns.rb

Defined Under Namespace

Classes: FuzzyPattern, Pattern, RegexpPattern

Instance Method Summary collapse

Instance Method Details

#choose(argument, pattern_opts, default: ?f) ⇒ Object



40
41
42
43
44
45
46
47
48
49
# File 'lib/utils/patterns.rb', line 40

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