require "insensitive_search/engine/base"
require "insensitive_search/in_dir"

module InsensitiveSearch
  module Engine
    class Linux < Base
      # - - - - - - - - - - - - - - - - - -
      # search

      def search(path_source)
        guard(path_source)

        parts = path_source.split(@delimiter)
        search_start(parts)
      end

      private

      # Start insensitive searching on Linux.
      #
      # The branch depends on whether
      # the argument as path is absolute or relative.
      #
      # @param [Array] parts the source for searching
      # @return [Array] search result
      def search_start(parts)
        parts[0] == '' \
            ? search_loop(parts[1..-1], '/')
            : search_loop(parts)
      end

      def search_loop(parts, prefix = '')
        list = in_dir(prefix, parts[0])

        list.inject([]) do |result, path|
          if parts.size > 1
            result |= search_loop(parts[1..-1], path)
          elsif @filter.ok?(path)
            result.push(path)
          end

          result
        end
      end

      def in_dir(dir, filename)
        InDir.new(dir).selected_list(filename)
      end
    end
  end
end
require "insensitive_search/engine/base"
require "insensitive_search/in_dir"

module InsensitiveSearch
  module Engine
    class Linux < Base
      # - - - - - - - - - - - - - - - - - -
      # search

      def search(path_source)
        guard(path_source)
        search_start(path_source)
      end

      private

      # Start insensitive searching on Linux.
      #
      # The branch depends on whether
      # the argument as path is absolute or relative.
      #
      # @param [String] path_source the source for searching
      # @return [Array] search result
      def search_start(path_source)
        parts = path_source.split(@delimiter)
        parts[0] == '' \
            ? search_loop(parts[1..-1], '/')
            : search_loop(parts)
      end

      def search_loop(parts, prefix = '')
        list = in_dir(prefix, parts[0])

        list.inject([]) do |result, path|
          if parts.size > 1
            result |= search_loop(parts[1..-1], path)
          elsif @filter.ok?(path)
            result.push(path)
          end

          result
        end
      end

      def in_dir(dir, filename)
        InDir.new(dir).selected_list(filename)
      end
    end
  end
end
Modify search funtions in Engine::Linux
Modify search funtions in Engine::Linux

InsensitiveSearch::Engine::Linux
----

- #search
  - Move the process to split path_source into #search_start.
  - Pass its argument to #search_start.
- #search_start
  - Change the argument.
  - Add the process to split path_source.
  - Fix YARD comment.
