Class: Timer
- Inherits:
-
Object
- Object
- Timer
- Defined in:
- lib/renamr/utils.rb
Overview
Returns string with humanized time interval.
Constant Summary collapse
- DIC =
[ [60, :seconds, :second], [60, :minutes, :minute], [24, :hours, :hour], [1000, :days, :day] ].freeze
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.
29 30 31 |
# File 'lib/renamr/utils.rb', line 29 def initialize @sta = Time.now end |
Instance Method Details
#humanize(sec) ⇒ Object
37 38 39 40 41 42 43 44 45 46 |
# File 'lib/renamr/utils.rb', line 37 def humanize(sec) return 'less than a second' if sec < 1 DIC.map do |cnt, nms, nm1| next if sec <= 0 sec, n = sec.divmod(cnt) "#{n.to_i} #{n.to_i != 1 ? nms : nm1}" end.compact.reverse.join(' ') end |
#read ⇒ Object
33 34 35 |
# File 'lib/renamr/utils.rb', line 33 def read humanize(Time.now - @sta) end |