Sha256: 6ee58a0f0e2a5e9889bc79639ea4be04d93e70f19ee758f9917eab48dc17b72d

Contents?: true

Size: 677 Bytes

Versions: 1

Compression:

Stored size: 677 Bytes

Contents

module LanguageCards
  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 #{I18n.t('Timer.AverageSeconds')}" % 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/timer.rb