Class: CheckpointTimer::Timer

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

Instance Attribute Summary collapse

Instance Method Summary collapse

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_counterObject (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_timeObject (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_allObject (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_timeObject (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_timeObject (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

Parameters:

  • message (String) (defaults to: nil)

Returns:

  • (Fixnum)

Raises:



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(message) if logging || log_all?
  elapsed_time
end

#startObject



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_timeFixnum

Returns:

  • (Fixnum)


37
38
39
# File 'lib/checkpoint_timer/timer.rb', line 37

def total_checkpoint_time
  current_time - start_time
end