<commit_before>module EventReporter
  class Find
    attr_reader :criteria,
                :printer

    def initialize(instream, outstream, printer, criteria)
      @instream   = instream
      @outstream  = outstream
      @printer    = printer
      @criteria   = criteria
    end

    def call
      return printer.invalid_find_command(criteria.join(" ")) if !valid_criteria?
      return printer.invalid_find_attribute(criteria[0]) if !valid_attribute?
      find_valid_entries
    end

    def find_valid_entries
      $entry_repository.nil? ? print_found(0) : find_entries
    end

    def valid_criteria?
      criteria.length == 2
    end

    def valid_attribute?
      valid_attributes = EventReporter::Entry.instance_methods(false).grep(/^((?!cleaner).)*$/)
      valid_attributes.include?(criteria[0].to_sym)
    end

    def find_entries
      found = get_matching_entries
      print_found(found.length)
      populate_queue(found)
    end

    def get_matching_entries
      $entry_repository.entries.select do |entry|
        entry.send(criteria[0].to_sym).downcase == criteria[1]
      end
    end

    def print_found(num)
      printer.print_number_found(num)
    end

    def populate_queue(found)
      $queue_repository = EventReporter::QueueRepository.new(found)
    end
  end
end<commit_msg>updated find to allow multi-word searching<commit_after>module EventReporter
  class Find
    attr_reader :criteria,
                :printer

    def initialize(instream, outstream, printer, criteria)
      @instream   = instream
      @outstream  = outstream
      @printer    = printer
      @criteria   = criteria
    end

    def call
      return printer.invalid_find_command(criteria.join(" ")) if !valid_criteria?
      return printer.invalid_find_attribute(criteria[0]) if !valid_attribute?
      find_valid_entries
    end

    def find_valid_entries
      $entry_repository.nil? ? print_found(0) : find_entries
    end

    def valid_criteria?
      criteria.length >= 2
    end

    def valid_attribute?
      valid_attributes = EventReporter::Entry.instance_methods(false).grep(/^((?!cleaner).)*$/)
      valid_attributes.include?(criteria[0].to_sym)
    end

    def find_entries
      search_criteria = criteria[1..-1].join(" ")
      found = get_matching_entries(search_criteria)
      print_found(found.length)
      populate_queue(found)
    end

    def get_matching_entries(search_criteria)
      $entry_repository.entries.select do |entry|
        entry.send(criteria[0].to_sym).downcase == search_criteria
      end
    end

    def print_found(num)
      printer.print_number_found(num)
    end

    def populate_queue(found)
      $queue_repository = EventReporter::QueueRepository.new(found)
    end
  end
end
{'fraction_non_alphanumeric': 0.08651399491094147, 'fraction_numerical': 0.004725554343874954, 'mean_word_length': 2.9597122302158274, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 4, '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': '2981386', 'n_tokens_mistral': 855, 'n_tokens_neox': 832, 'n_words': 160}