<commit_before>require 'colorize'

module HipchatSearcher
  class Searcher
    def initialize(result, options={})
      @result     = result
      @options    = options
      @print_room = false
    end

    def self.search(pattern, result, options)
      new(result, options).search(pattern)
    end

    def puts_search_result(pattern, item)
      msg = item.message.gsub(pattern) do |matched|
        matched.underline
      end

      date = "  Date: #{item.date}"
      name = item.from.mention_name rescue item.from
      msg  = "  @#{name}" + ': ' + msg

      if option_user?
        if @options[:user] == name
          puts_contents(date, msg)
        end
      else
        puts_contents(date, msg)
      end
    end

    def search(pattern)
      pattern = Regexp.new(pattern)

      @result.items.each do |item|
        if pattern =~ item.message
          puts_search_result(pattern, item)
        end
      end

      nil
    end

    private

    def option_user?
      !!@options[:user]
    end

    def print_room?
      !!@print_room<commit_msg>* Enable to search on Regexp::IGNORECASE<commit_after>require 'colorize'

module HipchatSearcher
  class Searcher
    def initialize(result, options={})
      @result     = result
      @options    = options
      @print_room = false
    end

    def self.search(pattern, result, options)
      new(result, options).search(pattern)
    end

    def puts_search_result(pattern, item)
      msg = item.message.gsub(pattern) do |matched|
        matched.underline
      end

      date = "  Date: #{item.date}"
      name = item.from.mention_name rescue item.from
      msg  = "  @#{name}" + ': ' + msg

      if option_user?
        if @options[:user] == name
          puts_contents(date, msg)
        end
      else
        puts_contents(date, msg)
      end
    end

    def search(pattern)
      pattern = Regexp.new(pattern, Regexp::IGNORECASE)

      @result.items.each do |item|
        if pattern =~ item.message
          puts_search_result(pattern, item)
        end
      end

      nil
    end

    private

    def option_user?
      !!@options[:user]
    end

    def print_room?
      !!@print_room
{'fraction_non_alphanumeric': 0.09839080459770115, 'fraction_numerical': 0.0, 'mean_word_length': 2.0433566433566432, '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': '224224', 'n_tokens_mistral': 684, 'n_tokens_neox': 669, 'n_words': 163}