<commit_before>require 'rubygems'
require 'g'

module Timer
  def time(message="")
    start_time = Time.now
    yield
    end_time = Time.now
    put_elapsed_time(start_time, end_time, message)
  end

  def put_elapsed_time(start_time, end_time, message="")
    seconds = end_time - start_time
    if seconds > 59
      minutes = seconds / 60.0
      seconds = (minutes - minutes.to_i) * 60

      m = minutes.to_i > 1 ? "minutes" : "minute"
      elapsed_time = "#{minutes.to_i} #{m}"
      if seconds > 0
        s = seconds.to_i > 1 ? "seconds" : "minutes"
        elapsed_time += ", #{seconds.to_i} #{s}"
      end
    else
      s = seconds.to_i > 1 ? "seconds" : "minutes"
      elapsed_time = "#{seconds.to_i} #{s}"
    end

    puts
    e = ""
    if message.strip != ""
      message += ". "
    end
    e = message + e
    e += "Elapsed time: #{elapsed_time}"
    puts e
    g(e)
  end
end<commit_msg>Handle growl a little more gracefully<commit_after>require 'rubygems'
require 'g'

module Timer
  def time(message="", options={})
    title = options[:title] || ""
    
    start_time = Time.now
    yield
    end_time = Time.now
    put_elapsed_time(start_time, end_time, message, title)
  end

  def put_elapsed_time(start_time, end_time, message="", title=nil)
    seconds = end_time - start_time
    if seconds > 59
      minutes = seconds / 60.0
      seconds = (minutes - minutes.to_i) * 60

      m = minutes.to_i > 1 ? "minutes" : "minute"
      elapsed_time = "#{minutes.to_i} #{m}"
      if seconds > 0
        s = seconds.to_i > 1 ? "seconds" : "minutes"
        elapsed_time += ", #{seconds.to_i} #{s}"
      end
    else
      s = seconds.to_i > 1 ? "seconds" : "minutes"
      elapsed_time = "#{seconds.to_i} #{s}"
    end

    puts
    e = ""
    if message.strip != ""
      message += ". "
    end
    e = message + e
    e += "Elapsed time: #{elapsed_time}"
    puts e
    if title
      g(e, :title => title)
    else
      g(e)
    end
  rescue StandardError => e
    # growl isn't turned on, fail silently
    unless e.message =~ /Connection refused/
      raise e
    end
  end
end
{'fraction_non_alphanumeric': 0.13191489361702127, 'fraction_numerical': 0.010401891252955082, 'mean_word_length': 2.250384024577573, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 15, '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': '6905716', 'n_tokens_mistral': 775, 'n_tokens_neox': 740, 'n_words': 196}