class ProgressBar

This class handles the incrementing and display of the progress bar.

Public Class Methods

new(title, max_progress) click to toggle source

Title can be any string, max_progress is in seconds.

# File lib/doro/progressbar.rb, line 13
def initialize(title, max_progress)
  @progress = 0
  @max_progress = max_progress
  @title = title
  @start_time = Time.now
  @interrupt = false
end

Public Instance Methods

start() { || ... } click to toggle source

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
# File lib/doro/progressbar.rb, line 29
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