<commit_before>require_relative 'config'

module FileSorter
  class FileSorter
    attr_reader :options

    def initialize(options = {})
      @options = default_options.merge(options)
    end

    def config
      @config ||= Config.load_file(options[:config_file]) if File.exists?(options[:config_file])
    end

    def sort!
      relevant_files.each do |filename|
        matcher = matcher_for(filename)
        next unless matcher
        puts "Handling #{filename} with #{matcher}" if verbose?
        matcher.handle(filename) unless options[:dry_run]
      end
    end

    def relevant_files
      config.folders.map do |folder|
        Dir.glob("#{folder}/*")
      end.inject(&:+)
    end

    private

    def matcher_for(filename)
      config.matchers.detect { |matcher| matcher.matches?(filename) }
    end

    def default_options
      {
        config_file: File.expand_path('~/.filesorter')
      }
    end

    def verbose?
      options[:verbose]
    end<commit_msg>Show handler verbiage on dry run<commit_after>require_relative 'config'

module FileSorter
  class FileSorter
    attr_reader :options

    def initialize(options = {})
      @options = default_options.merge(options)
    end

    def config
      @config ||= Config.load_file(options[:config_file]) if File.exists?(options[:config_file])
    end

    def sort!
      relevant_files.each do |filename|
        matcher = matcher_for(filename)
        next unless matcher
        puts "Handling #{filename} with #{matcher}" if verbose? or dry_run?
        matcher.handle(filename) unless dry_run?
      end
    end

    def relevant_files
      config.folders.map do |folder|
        Dir.glob("#{folder}/*")
      end.inject(&:+)
    end

    private

    def matcher_for(filename)
      config.matchers.detect { |matcher| matcher.matches?(filename) }
    end

    def default_options
      {
        config_file: File.expand_path('~/.filesorter')
      }
    end

    def verbose?
      options[:verbose]
    end

    def dry_run?
      options[:dry_run]
    end
{'fraction_non_alphanumeric': 0.10107421875, 'fraction_numerical': 0.0, 'mean_word_length': 2.575916230366492, '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': '1184809', 'n_tokens_mistral': 632, 'n_tokens_neox': 614, 'n_words': 142}