Sha256: 0bd94e81bab6d73e7b4ed6ed647dc3510af450d204697a5d1eb309667e05fa57

Contents?: true

Size: 665 Bytes

Versions: 7

Compression:

Stored size: 665 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

7 entries across 7 versions & 1 rubygems

Version Path
language_cards-0.3.2 lib/language_cards/timer.rb
language_cards-0.3.1 lib/language_cards/timer.rb
language_cards-0.3.0 lib/language_cards/timer.rb
language_cards-0.2.0 lib/language_cards/timer.rb
language_cards-0.1.3 lib/language_cards/timer.rb
language_cards-0.1.2 lib/language_cards/timer.rb
language_cards-0.1.1 lib/language_cards/timer.rb