Class: ProgressBar
Overview
Ruby/ProgressBar - a text progress bar library
Copyright © 2001-2005 Satoru Takabayashi <[email protected]> Copyright © 2010 Chris Gahan <[email protected]>
All rights reserved.
This is free software with ABSOLUTELY NO WARRANTY.
You can redistribute it and/or modify it under the terms of Ruby’s license.
Direct Known Subclasses
Constant Summary collapse
- VERSION =
"0.10"
Instance Attribute Summary collapse
-
#current ⇒ Object
readonly
Returns the value of attribute current.
-
#start_time ⇒ Object
Returns the value of attribute start_time.
-
#title ⇒ Object
readonly
Returns the value of attribute title.
-
#total ⇒ Object
readonly
Returns the value of attribute total.
Instance Method Summary collapse
- #clear ⇒ Object
- #file_transfer_mode ⇒ Object
- #finish ⇒ Object
- #finished? ⇒ Boolean
- #format=(format) ⇒ Object
- #format_arguments=(arguments) ⇒ Object
- #halt ⇒ Object
- #inc(step = 1) ⇒ Object
-
#initialize(title, total = nil, out = STDERR) ⇒ ProgressBar
constructor
A new instance of ProgressBar.
- #inspect ⇒ Object
- #set(count) ⇒ Object
Constructor Details
#initialize(title, total = nil, out = STDERR) ⇒ ProgressBar
Returns a new instance of ProgressBar.
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/epitools/progressbar.rb', line 16 def initialize (title, total=nil, out = STDERR) @title = title @total = total @out = out @terminal_width = 80 @bar_mark = "." @current = 0 @previous = 0 @finished_p = false @start_time = Time.now @previous_time = @start_time @title_width = 18 #@format = "%-#{@title_width}s %3d%% %s %s" if @total #@format_arguments = [:title, :percentage, :bar, :stat_for_file_transfer] @format_arguments = [:title, :percentage, :stat_for_file_transfer] else @format_arguments = [:title, :stat_for_file_transfer] end clear show end |
Instance Attribute Details
#current ⇒ Object (readonly)
Returns the value of attribute current.
41 42 43 |
# File 'lib/epitools/progressbar.rb', line 41 def current @current end |
#start_time ⇒ Object
Returns the value of attribute start_time.
43 44 45 |
# File 'lib/epitools/progressbar.rb', line 43 def start_time @start_time end |
#title ⇒ Object (readonly)
Returns the value of attribute title.
40 41 42 |
# File 'lib/epitools/progressbar.rb', line 40 def title @title end |
#total ⇒ Object (readonly)
Returns the value of attribute total.
42 43 44 |
# File 'lib/epitools/progressbar.rb', line 42 def total @total end |
Instance Method Details
#clear ⇒ Object
202 203 204 205 206 |
# File 'lib/epitools/progressbar.rb', line 202 def clear @out.print "\r" @out.print(" " * (get_width - 1)) @out.print "\r" end |
#file_transfer_mode ⇒ Object
218 219 220 |
# File 'lib/epitools/progressbar.rb', line 218 def file_transfer_mode @format_arguments = [:title, :percentage, :bar, :stat_for_file_transfer] end |
#finish ⇒ Object
208 209 210 211 212 |
# File 'lib/epitools/progressbar.rb', line 208 def finish @current = @total if @total @finished_p = true show end |
#finished? ⇒ Boolean
214 215 216 |
# File 'lib/epitools/progressbar.rb', line 214 def finished? @finished_p end |
#format=(format) ⇒ Object
222 223 224 |
# File 'lib/epitools/progressbar.rb', line 222 def format=(format) @format = format end |
#format_arguments=(arguments) ⇒ Object
226 227 228 |
# File 'lib/epitools/progressbar.rb', line 226 def format_arguments=(arguments) @format_arguments = arguments end |
#halt ⇒ Object
230 231 232 233 |
# File 'lib/epitools/progressbar.rb', line 230 def halt @finished_p = true show end |
#inc(step = 1) ⇒ Object
235 236 237 238 239 240 |
# File 'lib/epitools/progressbar.rb', line 235 def inc(step = 1) @current += step @current = @total if @total and @current > @total show_if_needed @previous = @current end |
#inspect ⇒ Object
251 252 253 |
# File 'lib/epitools/progressbar.rb', line 251 def inspect "#<ProgressBar:#{@current}/#{@total}>" end |
#set(count) ⇒ Object
242 243 244 245 246 247 248 249 |
# File 'lib/epitools/progressbar.rb', line 242 def set(count) if @total and (count < 0 || count > @total) raise "invalid count: #{count} (total: #{@total})" end @current = count show_if_needed @previous = @current end |