<commit_before>class GoDuration

  NANOSECOND=1.freeze
  MICROSECOND=1000*NANOSECOND.freeze
  MILLISECOND=1000*MICROSECOND.freeze
  SECOND=1000*MILLISECOND.freeze
  MINUTE=60*SECOND.freeze
  HOUR=60*MINUTE.freeze

  UNITS={
    'h' => HOUR,
    'm' => MINUTE,
    's' => SECOND,
    'ms' => MILLISECOND,
    'µs' => MICROSECOND,
    'us' => MICROSECOND,
    'ns' => NANOSECOND,
  }.freeze

  attr_reader :nanoseconds

  def initialize(v)
    @nanoseconds = parse(v)
  end

  def microseconds
    nanoseconds / MICROSECOND
  end

  def milliseconds
    nanoseconds / MILLISECOND
  end

  def seconds
    nanoseconds / SECOND
  end

  def minutes
    nanoseconds / MINUTE
  end

  def hours
    nanoseconds / HOUR
  end

  def format
    ns = nanoseconds
    fmt = ""

    UNITS.each do |unit, value|
      number, ns = ns.divmod(value)
      fmt << "#{number}#{unit}" if number > 0
    end

    fmt
  end

  private

  def parse(v)
    ns = 0

    while v.length > 0
      number = v.slice!(/[[:digit:]]+/).to_i
      unit = v.slice!(/[[:alpha:]]+/)

      raise "Invalid unit '#{unit}'" unless UNITS[unit]
      ns += (number * UNITS[unit])
    end

    ns
  end
end
<commit_msg>Cleanup and code comments<commit_after>module GoTime
  class Duration
    # One nanosecond
    NANOSECOND=1.freeze

    # One microsecond
    MICROSECOND=1000*NANOSECOND.freeze

    # One millisecond
    MILLISECOND=1000*MICROSECOND.freeze

    # One second
    SECOND=1000*MILLISECOND.freeze

    # One minute
    MINUTE=60*SECOND.freeze

    # One hour
    HOUR=60*MINUTE.freeze

    # A mapping of Go's unit notations to their nanosecond values.
    UNITS={
      "h" => HOUR,
      "m" => MINUTE,
      "s" => SECOND,
      "ms" => MILLISECOND,
      "µs" => MICROSECOND,
      "us" => MICROSECOND,
      "ns" => NANOSECOND,
    }.freeze

    attr_reader :nanoseconds

    # Initializes a new duration instance.
    #
    # @param ns [Fixnum] Duration in nanoseconds.
    #
    # @return [Duration]
    def initialize(ns)
      @nanoseconds = ns
    end

    # Parses a Go time.Duration string.
    #
    # @param duration [String] A Go duration string.
    #
    # @return [Duration]
    def self.parse(duration)
      ns = 0
      until duration.empty?
        number = duration.slice!(/^[[:digit:]]+/).to_i
        unit = duration.slice!(/^[[:alpha:]]+/)

        raise "Invalid unit '#{unit}'" unless UNITS[unit]
        ns += (number * UNITS[unit])
      end

      self.new(ns)
    end

    # Returns the number of microseconds in the duration.
    #
    # @return [Fixnum]
    def microseconds
      nanoseconds / MICROSECOND
    end

    # Returns the number of milliseconds in the duration.
    #
    # @return [Fixnum]
    def milliseconds
      nanoseconds / MILLISECOND
    end

    # Returns the number of seconds in the duration.
    #
    # @return [Fixnum]
    def seconds
      nanoseconds / SECOND
    end

    # Returns the number of minutes in the duration.
    #
    # @return [Fixnum]
    def minutes
      nanoseconds / MINUTE
    end

    # Returns the number of hours in the duration.
    #
    # @return [Fixnum]
    def hours
      nanoseconds / HOUR
    end

    # Returns the exact duration in nanoseconds.
    #
    # @return [Fixnum]
    def to_i
      nanoseconds
    end

    # Formats the duration into a Go duration string.
    #
    # @return [String]
    def to_s
      ns = nanoseconds
      fmt = ""

      UNITS.each do |unit, value|
        number, ns = ns.divmod(value)
        fmt << "#{number}#{unit}" if number > 0
      end

      fmt
    end
  end
end

{'fraction_non_alphanumeric': 0.1058068118369626, 'fraction_numerical': 0.010887772194304857, 'mean_word_length': 2.1512752858399296, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 20, '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': '5120303', 'n_tokens_mistral': 1346, 'n_tokens_neox': 1251, 'n_words': 327}