<commit_before>require 'ruby-duration'

module Dur

  def word_time_to_seconds(dur)
    match = dur.scan(/(\d+)\W(\w+)/)
    return dur unless match.length > 0
    seconds = 0
    match.each do |m|
      seconds += hour_min_sec_to_seconds(m[0], m[1])
    end
    seconds
  end

  def hour_min_sec_to_seconds(value, unit)
    seconds = 0
    if(%w.hr hrs hours hour h..include? unit)
      seconds += value.to_i * 3600
    end
    if(%w.mins min minutes minute m..include? unit)
      seconds += value.to_i * 60
    end
    if(%w.secs sec seconds second s..include? unit)
      seconds += value.to_i
    end
    return seconds
  end

  def seconds_to_iso8601(seconds)
    Duration.new(seconds).iso8601
  end
  
end<commit_msg>Fixing the regex to make more durable<commit_after>require 'ruby-duration'

module Dur

  def word_time_to_seconds(dur)
    
    return dur if /^\d+$/.match dur
    match = dur.scan(/(\d+)\s?(\w+)/)
    seconds = 0
    match.each do |m|
      seconds += hour_min_sec_to_seconds(m[0], m[1])
    end
    seconds
  end

  def hour_min_sec_to_seconds(value, unit)
    seconds = 0
    if(%w.hr hrs hours hour h..include? unit)
      seconds += value.to_i * 3600
    end
    if(%w.mins min minutes minute m..include? unit)
      seconds += value.to_i * 60
    end
    if(%w.secs sec seconds second s..include? unit)
      seconds += value.to_i
    end
    return seconds
  end

  def seconds_to_iso8601(seconds)
    Duration.new(seconds).iso8601
  end
  
end
{'fraction_non_alphanumeric': 0.11238997968855789, 'fraction_numerical': 0.025050778605280974, 'mean_word_length': 2.5528846153846154, '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': '6661333', 'n_tokens_mistral': 561, 'n_tokens_neox': 524, 'n_words': 137}