Class: Britebox::FileJobTimer
- Inherits:
-
Object
- Object
- Britebox::FileJobTimer
- Defined in:
- lib/britebox/file_job_timer.rb
Instance Attribute Summary collapse
-
#ended_at ⇒ Object
readonly
Returns the value of attribute ended_at.
-
#started_at ⇒ Object
readonly
Returns the value of attribute started_at.
Instance Method Summary collapse
- #duration ⇒ Object
-
#initialize ⇒ FileJobTimer
constructor
A new instance of FileJobTimer.
- #pause ⇒ Object
- #resume ⇒ Object
- #running? ⇒ Boolean
- #start ⇒ Object
- #stop ⇒ Object
Constructor Details
#initialize ⇒ FileJobTimer
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_at ⇒ Object (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_at ⇒ Object (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
#duration ⇒ Object
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 |
#pause ⇒ Object
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 |
#resume ⇒ Object
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
16 17 18 |
# File 'lib/britebox/file_job_timer.rb', line 16 def running? @is_running end |
#start ⇒ Object
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 |
#stop ⇒ Object
34 35 36 37 |
# File 'lib/britebox/file_job_timer.rb', line 34 def stop pause @ended_at = Time.now end |