<commit_before>require 'code_poetry/calculator'
require 'code_poetry/stat'
require 'code_poetry/formatter'
require 'code_poetry-html'

module CodePoetry
  class CLI
    DIRECOTRIES = %w[app lib]
    EXTENSIONS = %w[rb rake]

    def self.excecute(directories = DIRECOTRIES)
      files = Array(expand_directories_to_files(*directories)).compact
      calculator = Calculator.new(files)
      stats = calculator.calculate

      formatter = CodePoetry::Formatter::HTMLFormatter.new
      formatter.format(stats)
    end

  private

    def self.expand_directories_to_files(*directories)
      directories.flatten.map { |element|
        if File.directory?(element)
          Dir[expanded_diroctory_path(element)]
        else
          element
        end
      }.flatten.sort
    end

    def self.expanded_diroctory_path(directory)
      File.join(directory, "{#{DIRECOTRIES.join(',')}}**", '**', "*.{#{EXTENSIONS.join(',')}}")
    end
  end<commit_msg>Fixes the rake task without argument<commit_after>require 'code_poetry/calculator'
require 'code_poetry/stat'
require 'code_poetry/formatter'
require 'code_poetry-html'

module CodePoetry
  class CLI
    DIRECOTRIES = 'app,lib'
    EXTENSIONS = 'rb,rake'

    def self.excecute(path)
      files = Array(expand_directories_to_files(path).sort).compact
      calculator = Calculator.new(files)
      stats = calculator.calculate

      formatter = CodePoetry::Formatter::HTMLFormatter.new
      formatter.format(stats)
    end

  private

    def self.expand_directories_to_files(path)
      if path
        Dir[File.join(path, "{#{DIRECOTRIES}}**", '**', "*.{#{EXTENSIONS}}")]
      else
        FileList[File.join("{#{DIRECOTRIES}}**", '**', "*.{#{EXTENSIONS}}")]
      end
    end
  end
{'fraction_non_alphanumeric': 0.12743972445464982, 'fraction_numerical': 0.0, 'mean_word_length': 3.5155440414507773, 'pattern_counts': {'":': 0, '<': 3, '<?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': '1269194', 'n_tokens_mistral': 606, 'n_tokens_neox': 579, 'n_words': 97}