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.3"

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

#verbose(options = {:msec => true}) ⇒ Object



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