Class: CheckpointTimer::Timer
- Inherits:
-
Object
- Object
- CheckpointTimer::Timer
- Defined in:
- lib/checkpoint_timer/timer.rb
Instance Attribute Summary collapse
-
#checkpoint_counter ⇒ Object
readonly
Returns the value of attribute checkpoint_counter.
-
#current_time ⇒ Object
readonly
Returns the value of attribute current_time.
-
#log_all ⇒ Object
readonly
Returns the value of attribute log_all.
-
#previous_time ⇒ Object
readonly
Returns the value of attribute previous_time.
-
#start_time ⇒ Object
readonly
Returns the value of attribute start_time.
Instance Method Summary collapse
- #checkpoint(logging: false, message: nil) ⇒ Fixnum
-
#initialize(log_all: false) ⇒ Timer
constructor
A new instance of Timer.
- #start ⇒ Object
- #total_checkpoint_time ⇒ Fixnum
Constructor Details
#initialize(log_all: false) ⇒ Timer
Returns a new instance of Timer.
14 15 16 |
# File 'lib/checkpoint_timer/timer.rb', line 14 def initialize(log_all: false) @log_all = log_all end |
Instance Attribute Details
#checkpoint_counter ⇒ Object (readonly)
Returns the value of attribute checkpoint_counter.
8 9 10 |
# File 'lib/checkpoint_timer/timer.rb', line 8 def checkpoint_counter @checkpoint_counter end |
#current_time ⇒ Object (readonly)
Returns the value of attribute current_time.
8 9 10 |
# File 'lib/checkpoint_timer/timer.rb', line 8 def current_time @current_time end |
#log_all ⇒ Object (readonly)
Returns the value of attribute log_all.
8 9 10 |
# File 'lib/checkpoint_timer/timer.rb', line 8 def log_all @log_all end |
#previous_time ⇒ Object (readonly)
Returns the value of attribute previous_time.
8 9 10 |
# File 'lib/checkpoint_timer/timer.rb', line 8 def previous_time @previous_time end |
#start_time ⇒ Object (readonly)
Returns the value of attribute start_time.
8 9 10 |
# File 'lib/checkpoint_timer/timer.rb', line 8 def start_time @start_time end |
Instance Method Details
#checkpoint(logging: false, message: nil) ⇒ Fixnum
26 27 28 29 30 31 32 33 34 |
# File 'lib/checkpoint_timer/timer.rb', line 26 def checkpoint(logging: false, message: nil) raise TimerNotStartedError unless start_time @previous_time = current_time set_current_time iterate_counter log_checkpoint() if logging || log_all? elapsed_time end |
#start ⇒ Object
18 19 20 21 22 |
# File 'lib/checkpoint_timer/timer.rb', line 18 def start @checkpoint_counter = 0 @start_time = Time.now @current_time = start_time end |
#total_checkpoint_time ⇒ Fixnum
37 38 39 |
# File 'lib/checkpoint_timer/timer.rb', line 37 def total_checkpoint_time current_time - start_time end |