Sha256: def5eb4212bd4584b6c8d7f42d3df4e6edf159ea04b66daa36eb429893dfa4c6

Contents?: true

Size: 681 Bytes

Versions: 1

Compression:

Stored size: 681 Bytes

Contents

require "stop_watch/version"

module StopWatch
  class Timer
    def initialize
      @stamps = []
      @mark = nil
    end

    def mark
      if @mark
        @stamps << -(@mark - (@mark = Time.now))
      else
        @mark = Time.now
      end
    end

    def time?
      !times.empty?
    end

    def h # human
      "%02d:%02d:%02d" % [total/3600%24, total/60%60, total%60]
    end

    def average
      total.fdiv(times.size)
    end

    def ha # human average

      "%0.2f second average" % average
    rescue
      ""

    end

    def times
      @stamps
    end

    def last
      @stamps.last
    end

    def total
      @stamps.inject(0, :+)
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
stop_watch-0.1.0 lib/stop_watch.rb