<commit_before>
module CoreUtils

  def self.find_class(name)
    if name.class == String
      name = name.gsub(/::(\w)| (\w)/, &:upcase).tr(' ','')
    end
    return Kernel.const_get(name)
  end

  def self.recursively_print_hash(hash, truncate=false,indent='')
    print "#{indent}{\n"
    hash.each_pair do |key, value|
      if value.class == Hash
        print "#{indent}#{key} =>\n"
        recursively_print_hash(value, truncate, indent+"    ")
      elsif value.class == Array
        print "#{indent}#{key} =>\n"
        recursively_print_array(value, truncate, indent+"    ")
      elsif value.class < Struct
        print "#{indent}#{key} =>\n"
        recursively_print_hash(value.to_h, truncate, indent+"    ")
      else
        if truncate and value.respond_to? :size
          print "#{indent}#{key} => #{value.size > 50 ? value[0..50]+"..." : value}\n"
        else
          print "#{indent}#{key} => #{value}\n"
        end
      end
    end
    print "#{indent}}\n"
  end

  def self.recursively_print_array(array, truncate=false, indent="")
    print "#{indent}[\n"
    array.each do |item|
      if item.class == Array
        recursively_print_array(item, truncate, indent+"    ")
      elsif item.class == Hash
        recursively_print_hash(item, truncate, indent+"    ")
      elsif item.class < Struct
        recursively_print_hash(item.to_h, truncate, indent+"    ")
      else
        if truncate and item.respond_to? :size
          print "#{indent}#{item.size > 50 ? item[0..50]+"..." : item}\n"
        else
          print "#{indent}#{item}\n"
        end
      end
    end
    print "#{indent}]\n"
  end

  def self.wait_until(timeout, &block)
    begin
      Watir::Wait.until(timeout: timeout, &block)
      return true
    rescue Watir::Wait::TimeoutError => e
      return false
    end
  end

  def self.wait_safely(timeout, &block)

    safety_block = Proc.new {
      begin
        block.call
        true
      rescue
        false
      end
    }

    begin
      Watir::Wait.until(timeout: timeout, &safety_block)
      return true
    rescue Watir::Wait::TimeoutError => e
      return false
    end
  end

end
<commit_msg>per code review over discord<commit_after>
module CoreUtils

  def self.find_class(name)
    if name.class == String
      name = name.gsub(/::(\w)| (\w)/, {|match| match.upcase}).tr(' ','')
    end
    return Kernel.const_get(name)
  end

  def self.recursively_print_hash(hash, truncate=false,indent='')
    print "#{indent}{\n"
    hash.each_pair do |key, value|
      if value.class == Hash
        print "#{indent}#{key} =>\n"
        recursively_print_hash(value, truncate, indent+"    ")
      elsif value.class == Array
        print "#{indent}#{key} =>\n"
        recursively_print_array(value, truncate, indent+"    ")
      elsif value.class < Struct
        print "#{indent}#{key} =>\n"
        recursively_print_hash(value.to_h, truncate, indent+"    ")
      else
        if truncate and value.respond_to? :size
          print "#{indent}#{key} => #{value.size > 50 ? value[0..50]+"..." : value}\n"
        else
          print "#{indent}#{key} => #{value}\n"
        end
      end
    end
    print "#{indent}}\n"
  end

  def self.recursively_print_array(array, truncate=false, indent="")
    print "#{indent}[\n"
    array.each do |item|
      if item.class == Array
        recursively_print_array(item, truncate, indent+"    ")
      elsif item.class == Hash
        recursively_print_hash(item, truncate, indent+"    ")
      elsif item.class < Struct
        recursively_print_hash(item.to_h, truncate, indent+"    ")
      else
        if truncate and item.respond_to? :size
          print "#{indent}#{item.size > 50 ? item[0..50]+"..." : item}\n"
        else
          print "#{indent}#{item}\n"
        end
      end
    end
    print "#{indent}]\n"
  end

  def self.wait_until(timeout, &block)
    begin
      Watir::Wait.until(timeout: timeout, &block)
      return true
    rescue Watir::Wait::TimeoutError => e
      return false
    end
  end

  def self.wait_safely(timeout, &block)

    safety_block = Proc.new {
      begin
        block.call
        true
      rescue
        false
      end
    }

    begin
      Watir::Wait.until(timeout: timeout, &safety_block)
      return true
    rescue Watir::Wait::TimeoutError => e
      return false
    end
  end

end

{'fraction_non_alphanumeric': 0.14115762983299016, 'fraction_numerical': 0.004575611988103409, 'mean_word_length': 2.255398361876396, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 21, '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': '5075298', 'n_tokens_mistral': 1444, 'n_tokens_neox': 1428, 'n_words': 329}