Class: Clocker
- Inherits:
-
Object
- Object
- Clocker
- Defined in:
- lib/clocker.rb,
lib/clocker/version.rb
Overview
lib/clocker/version.rb Version of Clocker
Constant Summary collapse
- VERSION =
'0.1.6'
Instance Attribute Summary collapse
-
#options ⇒ Object
Returns the value of attribute options.
Instance Method Summary collapse
- #clock(&block) ⇒ Object
-
#initialize(options = {}) ⇒ Clocker
constructor
A new instance of Clocker.
- #stop ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ Clocker
Returns a new instance of Clocker.
10 11 12 |
# File 'lib/clocker.rb', line 10 def initialize( = {}) self. = end |
Instance Attribute Details
#options ⇒ Object
Returns the value of attribute options.
8 9 10 |
# File 'lib/clocker.rb', line 8 def end |
Instance Method Details
#clock(&block) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/clocker.rb', line 14 def clock(&block) @start = Time.now if [:show_messages] puts "\nstart: #{@start}" end begin block.call rescue StandardError => e puts e. end return stop end |
#stop ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/clocker.rb', line 30 def stop @stop = Time.now if [:show_messages] puts "\nended: #{@stop}" end ms = ((@stop - @start) * 1000).to_i if ms > 60000 mins = ms / 60000 ms = ms - (60000 * mins) if ms > 1000 secs = ms / 1000 ms = ms % 1000 end return { mins: mins, secs: secs, ms: ms } elsif ms > 1000 secs = ms / 1000 ms = ms % 1000 return { mins: 0, secs: secs, ms: ms } else return { mins: 0, secs: 0, ms: ms } end end |