Class: Timer
- Inherits:
-
Object
- Object
- Timer
- Defined in:
- lib/transcode/timer.rb
Overview
Measures elapsed time and reports it as a humanized string.
Constant Summary collapse
- DIC =
[ [60, :seconds, :second], [60, :minutes, :minute], [24, :hours, :hour], [1000, :days, :day] ].freeze
Class Attribute Summary collapse
-
.less_sec ⇒ Object
readonly
Returns the value of attribute less_sec.
Instance Method Summary collapse
- #humanize(sec) ⇒ Object
-
#initialize ⇒ Timer
constructor
A new instance of Timer.
- #read ⇒ Object
Constructor Details
#initialize ⇒ Timer
Returns a new instance of Timer.
21 22 23 |
# File 'lib/transcode/timer.rb', line 21 def initialize @sta = Time.now end |
Class Attribute Details
.less_sec ⇒ Object (readonly)
Returns the value of attribute less_sec.
11 12 13 |
# File 'lib/transcode/timer.rb', line 11 def less_sec @less_sec end |
Instance Method Details
#humanize(sec) ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/transcode/timer.rb', line 29 def humanize(sec) return '' if sec.nil? return Timer.less_sec if sec < 1 DIC.filter_map do |cnt, nms, nm1| next if sec <= 0 sec, n = sec.divmod(cnt) "#{n.to_i} #{n.to_i == 1 ? nm1 : nms}" end.compact.reverse.join(' ') end |
#read ⇒ Object
25 26 27 |
# File 'lib/transcode/timer.rb', line 25 def read humanize(Time.now - @sta) end |