Class: Reviewer::Shell::Timer
- Inherits:
-
Object
- Object
- Reviewer::Shell::Timer
- Defined in:
- lib/reviewer/shell/timer.rb
Overview
Provides a structured interface for measuring realtime main while running comamnds
Instance Attribute Summary collapse
-
#main ⇒ Object
Returns the value of attribute main.
-
#prep ⇒ Object
Returns the value of attribute prep.
Instance Method Summary collapse
-
#initialize(prep: nil, main: nil) ⇒ self
constructor
A ‘Smart’ timer that understands preparation time and main time and can easily do the math to help determine what percentage of time was prep.
- #main_seconds ⇒ Object
- #prep_percent ⇒ Object
- #prep_seconds ⇒ Object
- #prepped? ⇒ Boolean
-
#record_main(&block) ⇒ Float
Records the execution time for the block and assigns it to the ‘main` time.
-
#record_prep(&block) ⇒ Float
Records the execution time for the block and assigns it to the ‘prep` time.
- #total ⇒ Object
- #total_seconds ⇒ Object
Constructor Details
#initialize(prep: nil, main: nil) ⇒ self
A ‘Smart’ timer that understands preparation time and main time and can easily do the math
to help determine what percentage of time was prep. The times can be passed in directly or
recorded using the `record_prep` and `record_main` methods
18 19 20 21 |
# File 'lib/reviewer/shell/timer.rb', line 18 def initialize(prep: nil, main: nil) @prep = prep @main = main end |
Instance Attribute Details
#main ⇒ Object
Returns the value of attribute main.
9 10 11 |
# File 'lib/reviewer/shell/timer.rb', line 9 def main @main end |
#prep ⇒ Object
Returns the value of attribute prep.
9 10 11 |
# File 'lib/reviewer/shell/timer.rb', line 9 def prep @prep end |
Instance Method Details
#main_seconds ⇒ Object
43 44 45 |
# File 'lib/reviewer/shell/timer.rb', line 43 def main_seconds main.round(2) end |
#prep_percent ⇒ Object
51 52 53 54 55 |
# File 'lib/reviewer/shell/timer.rb', line 51 def prep_percent return nil unless prepped? (prep / total.to_f * 100).round end |
#prep_seconds ⇒ Object
39 40 41 |
# File 'lib/reviewer/shell/timer.rb', line 39 def prep_seconds prep.round(2) end |
#prepped? ⇒ Boolean
61 62 63 |
# File 'lib/reviewer/shell/timer.rb', line 61 def prepped? !(prep.nil? || main.nil?) end |
#record_main(&block) ⇒ Float
Records the execution time for the block and assigns it to the ‘main` time
35 36 37 |
# File 'lib/reviewer/shell/timer.rb', line 35 def record_main(&block) @main = record(&block) end |
#record_prep(&block) ⇒ Float
Records the execution time for the block and assigns it to the ‘prep` time
27 28 29 |
# File 'lib/reviewer/shell/timer.rb', line 27 def record_prep(&block) @prep = record(&block) end |
#total ⇒ Object
57 58 59 |
# File 'lib/reviewer/shell/timer.rb', line 57 def total [prep, main].compact.sum end |
#total_seconds ⇒ Object
47 48 49 |
# File 'lib/reviewer/shell/timer.rb', line 47 def total_seconds total.round(2) end |