Class: ProgressBar
- Inherits:
-
Object
- Object
- ProgressBar
- Defined in:
- lib/doro/progressbar.rb
Overview
This class handles the incrementing and display of the progress bar.
Instance Method Summary collapse
-
#initialize(title, max_progress) ⇒ ProgressBar
constructor
Title can be any string, max_progress is in seconds.
-
#start ⇒ Object
This starts the timer.
Constructor Details
#initialize(title, max_progress) ⇒ ProgressBar
Title can be any string, max_progress is in seconds.
10 11 12 13 14 15 16 |
# File 'lib/doro/progressbar.rb', line 10 def initialize(title, max_progress) @progress = 0 @max_progress = max_progress @title = title @start_time = Time.now @interrupt = false end |
Instance Method Details
#start ⇒ Object
This starts the timer. It accepts a block which allows you plug in other behaviors (such as incrementing another timer outside of the class). You’d do something like:
ProgressBar.new("Example", 60).start do |t|
p 'this fires every second'
end
25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/doro/progressbar.rb', line 25 def start Signal.trap("INT") { @interrupt = true } while (@progress <= @max_progress && @interrupt == false ) render_progress @progress += 1 yield sleep 1 end print("\r") display_notification end |