easy_timer 0.9.2 → 0.9.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,3 +1,3 @@
1
1
  module EasyTimer
2
- VERSION = "0.9.2"
2
+ VERSION = "0.9.3"
3
3
  end
data/lib/easy_timer.rb CHANGED
@@ -5,7 +5,7 @@ module EasyTimer
5
5
  base.extend(ClassMethods)
6
6
  end
7
7
 
8
- module ClassMethods
8
+ module ClassMethods
9
9
  def timer(options = {}, &block)
10
10
  start_time = Time.now
11
11
  yield
@@ -16,24 +16,24 @@ module EasyTimer
16
16
  return total_time
17
17
  end
18
18
  end
19
- end
19
+ end
20
20
 
21
- def verbose
21
+ def verbose(options = {:msec => true})
22
22
  time_hash = {}
23
23
  seconds = self.to_i
24
- milliseconds = (self.to_f - seconds)
25
- time_hash[:weeks], seconds = seconds.divmod(604800)
26
- time_hash[:days], seconds = seconds.divmod(86400)
27
- time_hash[:hours], seconds = seconds.divmod(3600)
28
- time_hash[:minutes], seconds = seconds.divmod(60)
29
- time_hash[:seconds] = seconds + milliseconds
30
- return time_hash.select{|k,v| v > 0}.inject([]){|verbose, array|
24
+ time_hash[:week], seconds = seconds.divmod(604800)
25
+ time_hash[:day], seconds = seconds.divmod(86400)
26
+ time_hash[:hour], seconds = seconds.divmod(3600)
27
+ time_hash[:minute], seconds = seconds.divmod(60)
28
+ time_hash[:second] = seconds
29
+ time_hash[:second] += (self.to_f - self.to_i) if options[:msec]
30
+ return time_hash.select{|k,v| v > 0}.inject([]) do |verbose, array|
31
31
  k, v = array
32
- verbose << "#{v.is_a?(Float) ? sprintf("%.2f", v) : v} #{v > 1 ? k : k.to_s.chars.to_a[0..-2].join}"
33
- }.join(" ")
32
+ verbose << "#{v.is_a?(Float) ? sprintf("%.2f", v) : v} #{k.to_s + (v == 1 ? '' : 's')}"
33
+ end.join(" ")
34
34
  end
35
35
  end
36
36
 
37
37
  class Time
38
38
  include EasyTimer
39
- end
39
+ end
@@ -14,8 +14,8 @@ describe "timer instance" do
14
14
  expect(Time.at(1389722.22).verbose).to eql "2 weeks 2 days 2 hours 2 minutes 2.22 seconds"
15
15
  end
16
16
 
17
- it "should show 1 seconds" do
18
- expect(Time.timer{sleep 1}.verbose).to eql "1.00 seconds"
17
+ it "should show 0.55 seconds" do
18
+ expect(Time.timer{sleep 0.55}.verbose).to eql "0.55 seconds"
19
19
  end
20
20
  end
21
21
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: easy_timer
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.2
4
+ version: 0.9.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: