class Utils::Finder
def search_paths(paths)
def search_paths(paths) suffixes = Array(@args[?I]) suffixes.full? do |s| paths.select! { |path| s.include?(File.extname(path)[1..-1]) } end paths = paths.map! do |path| if @pattern.nil? [ [ path.count(?/), path ], path, path ] elsif match = @pattern.match(path) if FuzzyPattern === @pattern current = 0 marked_path = '' score, e = path.size, nil for i in 1...match.size match[i] or next b = match.begin(i) e ||= b marked_path << path[current...b] marked_path << red(path[b, 1]) score += (b - e) * (path.size - b) e = match.end(i) current = b + 1 end marked_path << match.post_match [ score, path, marked_path ] else marked_path = path[0...match.begin(0)] << red(path[match.begin(0)...match.end(0)]) << path[match.end(0)..-1] [ 0, path, marked_path ] end end end paths.compact! @paths, @output = paths.sort.transpose.values_at(-2, -1) if n = @args[?n]&.to_i @paths = @paths&.first(n) || [] @output = @output&.first(n) || [] end self end