<commit_before>require_relative 'repo'

module RepoFinder
  class << self

    def repos_in_or_below(directory)
      if all_child_folders_have_repos(directory) # Base case
        repos_in(directory)

      else
        repos = repos_in(directory)

        folders_without_repos_in(directory).each do |folder|
          repos += repos_in_or_below(folder)
        end

        repos
      end
    end



    private

    def repos_in(directory)
      return [] if folders_in(directory).empty?

      folders_with_repos_in(directory).map { |d| Repo.new(d) }
    end

    def folders_without_repos_in(directory)
      directories = folders_in(directory)

      directories.reject { |d| contains_repo?(d) }
    end

    def folders_with_repos_in(directory)
      directories = folders_in(directory)
      directories.select { |d| contains_repo?(d) }
    end

    def all_child_folders_have_repos(directory)
      folders_with_repos_in(directory).sort == folders_in(directory).sort
    end

    def contains_repo?(directory_path)
      Dir.glob("#{directory_path}/.git").any?
    end

    def folders_in(directory)
      Dir.glob("#{directory}/*")
    end
  end
end<commit_msg>refactor to fewer methods in Repo class<commit_after>require_relative 'repo'

module RepoFinder
  class << self

    def repos_in_or_below(directory)
      repos_in(directory) + repos_in_subdirectories_of(directory)
    end



    private

    def repos_in(directory)
      folders_with_repos_in(directory).map { |d| Repo.new(d) }
    end

    def folders_with_repos_in(directory)
      directories = subdirectories_in(directory)
      directories.select { |d| contains_repo?(d) }
    end

    def repos_in_subdirectories_of(directory)
      subdirectories = subdirectories_in(directory)

      subdirectories.reduce([]) do |repos, subdirectory| 
        repos += repos_in_or_below(subdirectory)
      end
    end

    def contains_repo?(directory_path)
      Dir.glob("#{directory_path}/.git").any?
    end

    def subdirectories_in(directory)
      Dir.glob("#{directory}/*")
    end
  end
end
{'fraction_non_alphanumeric': 0.09183180280328661, 'fraction_numerical': 0.0, 'mean_word_length': 3.1566265060240966, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5502194', 'n_tokens_mistral': 710, 'n_tokens_neox': 653, 'n_words': 119}