Module: Treebis::DirAsHash::Blacklist::MatcherFactory

Overview

ruby implementation of fileglob-like patterns for data structures this would be faster and uglier with string matchers as hash keys this might move to Tardo lib

Instance Method Summary collapse

Instance Method Details

#create_matcher(mixed) ⇒ Object



180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
# File 'lib/treebis.rb', line 180

def create_matcher mixed
  case mixed
  when Matcher; mixed # keep this first for primitive subclasses
  when NilClass; EmptyMatcher
  when String
    %r{\A([^/]+)(?:/(.+)|)\Z} =~ mixed or
      fail("path: #{mixed.inspect}")
    head, tail = $1, $2
    if head.index('*')
      GlobNodeMatcher.get(head, tail)
    else
      StringMatcher.new(head, tail)
    end
  when Array; Blacklist.new(mixed)
  else
    fail("can't build matcher from #{mixed.inspect}")
  end
end