Class: LanguageCards::Timer
- Inherits:
-
Object
- Object
- LanguageCards::Timer
- Defined in:
- lib/language_cards/timer.rb
Instance Method Summary collapse
- #average ⇒ Object
-
#h ⇒ Object
human.
-
#ha ⇒ Object
human average.
-
#initialize ⇒ Timer
constructor
A new instance of Timer.
- #last ⇒ Object
- #mark ⇒ Object
- #time? ⇒ Boolean
- #times ⇒ Object
- #total ⇒ Object
Constructor Details
#initialize ⇒ Timer
Returns a new instance of Timer.
4 5 6 7 |
# File 'lib/language_cards/timer.rb', line 4 def initialize @stamps = [] @mark = nil end |
Instance Method Details
#average ⇒ Object
25 26 27 |
# File 'lib/language_cards/timer.rb', line 25 def average total.fdiv(times.size) end |
#h ⇒ Object
human
21 22 23 |
# File 'lib/language_cards/timer.rb', line 21 def h # human "%02d:%02d:%02d" % [total/3600%24, total/60%60, total%60] end |
#ha ⇒ Object
human average
29 30 31 |
# File 'lib/language_cards/timer.rb', line 29 def ha # human average "%0.2f #{I18n.t('Timer.AverageSeconds')}" % average rescue "" end |
#last ⇒ Object
37 38 39 |
# File 'lib/language_cards/timer.rb', line 37 def last @stamps.last end |
#mark ⇒ Object
9 10 11 12 13 14 15 |
# File 'lib/language_cards/timer.rb', line 9 def mark if @mark @stamps << -(@mark - (@mark = Time.now)) else @mark = Time.now end end |
#time? ⇒ Boolean
17 18 19 |
# File 'lib/language_cards/timer.rb', line 17 def time? !times.empty? end |
#times ⇒ Object
33 34 35 |
# File 'lib/language_cards/timer.rb', line 33 def times @stamps end |
#total ⇒ Object
41 42 43 |
# File 'lib/language_cards/timer.rb', line 41 def total @stamps.inject(:+) || 0 end |