21
22
23
24
25
26
27
28
29
30
31
32
33
34
|
# File 'lib/easy_timer.rb', line 21
def verbose(options = {:msec => true})
time_hash = {}
seconds = self.to_i
time_hash[:week], seconds = seconds.divmod(604800)
time_hash[:day], seconds = seconds.divmod(86400)
time_hash[:hour], seconds = seconds.divmod(3600)
time_hash[:minute], seconds = seconds.divmod(60)
time_hash[:second] = seconds
time_hash[:second] += (self.to_f - self.to_i) if options[:msec]
return time_hash.select{|k,v| v > 0}.inject([]) do |verbose, array|
k, v = array
verbose << "#{v.is_a?(Float) ? sprintf("%.2f", v) : v} #{k.to_s + (v == 1 ? '' : 's')}"
end.join(" ")
end
|