Class | Clio::Progressbar |
In: |
lib/clio/progressbar.rb
|
Parent: | Object |
Progressbar is a console-based progress bar library.
pbar = ProgressBar.new( "Demo", 100 ) 100.times { pbar.inc } pbar.finish
Based-on the original ProgressBar library by Satoru Takabayashi
Copyright (C) 2001 Satoru Takabayashi
# File lib/clio/progressbar.rb, line 21 def initialize(title, total, out = STDERR) @title = title @total = total @out = out @bar_length = 80 @bar_mark = "o" @total_overflow = true @current = 0 @previous = 0 @is_finished = false @start_time = Time.now @format = "%-14s %3d%% %s %s" @format_arguments = [:title, :percentage, :bar, :stat] show_progress end
# File lib/clio/progressbar.rb, line 164 def file_transfer_mode @format_arguments = [:title, :percentage, :bar, :stat_for_file_transfer] end
# File lib/clio/progressbar.rb, line 188 def finish @current = @total @is_finished = true show_progress end
# File lib/clio/progressbar.rb, line 184 def format_arguments=(arguments) @format_arguments = arguments end
# File lib/clio/progressbar.rb, line 218 def inc(step = 1) @current += step @current = @total if @current > @total show_progress @previous = @current end
# File lib/clio/progressbar.rb, line 203 def set(count) if count < 0 raise "invalid count less than zero: #{count}" elsif count > @total if @total_overflow @total = count + 1 else raise "invalid count greater than total: #{count}" end end @current = count show_progress @previous = @current end