Module: EasyTimer

Included in:
Time
Defined in:
lib/easy_timer.rb,
lib/easy_timer/version.rb

Defined Under Namespace

Modules: ClassMethods

Constant Summary collapse

VERSION =
"0.9.2"

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object



4
5
6
# File 'lib/easy_timer.rb', line 4

def self.included(base)
  base.extend(ClassMethods)
end

Instance Method Details

#verboseObject



21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/easy_timer.rb', line 21

def verbose
  time_hash = {}
  seconds = self.to_i
  milliseconds = (self.to_f - seconds)
  time_hash[:weeks], seconds = seconds.divmod(604800)
  time_hash[:days], seconds = seconds.divmod(86400)
  time_hash[:hours], seconds = seconds.divmod(3600)
  time_hash[:minutes], seconds = seconds.divmod(60)
  time_hash[:seconds] = seconds + milliseconds
  return time_hash.select{|k,v| v > 0}.inject([]){|verbose, array|
    k, v = array
    verbose << "#{v.is_a?(Float) ? sprintf("%.2f", v) : v} #{v > 1 ? k : k.to_s.chars.to_a[0..-2].join}"
  }.join(" ")
end