Class: Reviewer::Shell::Timer

Inherits:
Object
  • Object
show all
Defined in:
lib/reviewer/shell/timer.rb

Overview

Provides a structured interface for measuring realtime main while running comamnds

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(prep: nil, main: nil) ⇒ Timer

A timer that tracks preparation and main execution times separately. Times can be passed directly or recorded using record_prep and record_main.



21
22
23
24
# File 'lib/reviewer/shell/timer.rb', line 21

def initialize(prep: nil, main: nil)
  @prep = prep
  @main = main
end

Instance Attribute Details

#mainObject

Returns the value of attribute main.



13
# File 'lib/reviewer/shell/timer.rb', line 13

attr_reader :prep, :main

#prepFloat?



13
14
15
# File 'lib/reviewer/shell/timer.rb', line 13

def prep
  @prep
end

Instance Method Details

#main_secondsFloat

The main execution time rounded to two decimal places



46
# File 'lib/reviewer/shell/timer.rb', line 46

def main_seconds = main.round(2)

#prep_percentInteger?

The percentage of total time spent on preparation



66
67
68
69
70
# File 'lib/reviewer/shell/timer.rb', line 66

def prep_percent
  return nil unless prepped?

  (prep / total.to_f * 100).round
end

#prep_secondsFloat

The preparation time rounded to two decimal places



41
# File 'lib/reviewer/shell/timer.rb', line 41

def prep_seconds = prep.round(2)

#prepped?Boolean

Whether both prep and main times have been recorded



61
# File 'lib/reviewer/shell/timer.rb', line 61

def prepped? = [prep, main].all?

#record_mainFloat

Records the execution time for the block and assigns it to the main time



36
# File 'lib/reviewer/shell/timer.rb', line 36

def record_main(&) = @main = record(&)

#record_prepFloat

Records the execution time for the block and assigns it to the prep time



30
# File 'lib/reviewer/shell/timer.rb', line 30

def record_prep(&) = @prep = record(&)

#totalFloat

The total time (prep + main) without rounding



56
# File 'lib/reviewer/shell/timer.rb', line 56

def total = [prep, main].compact.sum

#total_secondsFloat

The total execution time (prep + main) rounded to two decimal places



51
# File 'lib/reviewer/shell/timer.rb', line 51

def total_seconds = total.round(2)