Class: Britebox::FileJobTimer

Inherits:
Object
  • Object
show all
Defined in:
lib/britebox/file_job_timer.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeFileJobTimer

Returns a new instance of FileJobTimer.



5
6
7
8
# File 'lib/britebox/file_job_timer.rb', line 5

def initialize
  @banked_time = 0
  @is_running = false
end

Instance Attribute Details

#ended_atObject (readonly)

Returns the value of attribute ended_at.



3
4
5
# File 'lib/britebox/file_job_timer.rb', line 3

def ended_at
  @ended_at
end

#started_atObject (readonly)

Returns the value of attribute started_at.



3
4
5
# File 'lib/britebox/file_job_timer.rb', line 3

def started_at
  @started_at
end

Instance Method Details

#durationObject



39
40
41
42
43
44
45
# File 'lib/britebox/file_job_timer.rb', line 39

def duration
  if running?
    @banked_time + (Time.now - @resumed_at)
  else
    @banked_time
  end
end

#pauseObject



20
21
22
23
24
25
# File 'lib/britebox/file_job_timer.rb', line 20

def pause
  return unless running?

  @is_running = false
  @banked_time += (Time.now - @resumed_at)
end

#resumeObject



27
28
29
30
31
32
# File 'lib/britebox/file_job_timer.rb', line 27

def resume
  return if running?

  @resumed_at = Time.now
  @is_running = true
end

#running?Boolean

Returns:

  • (Boolean)


16
17
18
# File 'lib/britebox/file_job_timer.rb', line 16

def running?
  @is_running
end

#startObject



10
11
12
13
14
# File 'lib/britebox/file_job_timer.rb', line 10

def start
  @banked_time = 0
  @started_at = @resumed_at = Time.now
  @is_running = true
end

#stopObject



34
35
36
37
# File 'lib/britebox/file_job_timer.rb', line 34

def stop
  pause
  @ended_at = Time.now
end