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 =
'1.0.2'
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.
7 8 9 |
# File 'lib/clocker.rb', line 7 def initialize( = {}) self. = end |
Instance Attribute Details
#options ⇒ Object
Returns the value of attribute options.
5 6 7 |
# File 'lib/clocker.rb', line 5 def @options end |
Instance Method Details
#clock(&block) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/clocker.rb', line 11 def clock(&block) @start = Time.now if [:show_messages] puts "\nstart: #{@start}" end begin block.call rescue puts "ERROR: invalid command or block" end return stop end |
#stop ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/clocker.rb', line 27 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 |