Class: ProgressBar
- Inherits:
-
Object
- Object
- ProgressBar
- Defined in:
- lib/progressbar.rb
Overview
Ruby/ProgressBar - a text progress bar library
Copyright (C) 2001-2005 Satoru Takabayashi <satoru@namazu.org>
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
- VERSION =
"0.9"
Instance Attribute Summary (collapse)
-
- (Object) bar_mark
writeonly
Sets the attribute bar_mark.
-
- (Object) current
readonly
Returns the value of attribute current.
-
- (Object) start_time
Returns the value of attribute start_time.
-
- (Object) title
readonly
Returns the value of attribute title.
-
- (Object) total
readonly
Returns the value of attribute total.
Instance Method Summary (collapse)
- - (Object) clear
- - (Object) file_transfer_mode
- - (Object) finish
- - (Boolean) finished?
- - (Object) format=(format)
- - (Object) format_arguments=(arguments)
- - (Object) halt
- - (Object) inc(step = 1)
-
- (ProgressBar) initialize(title, total, out = STDERR)
constructor
A new instance of ProgressBar.
- - (Object) inspect
- - (Object) set(count)
Constructor Details
- (ProgressBar) initialize(title, total, out = STDERR)
A new instance of ProgressBar
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/progressbar.rb', line 15 def initialize (title, total, out = STDERR) @title = title @total = total @out = out @terminal_width = 80 @bar_mark = "o" @current = 0 @previous = 0 @finished_p = false @start_time = Time.now @previous_time = @start_time @title_width = 14 @format = "%-#{@title_width}s %3d%% %s %s" @format_arguments = [:title, :percentage, :bar, :stat] clear show end |
Instance Attribute Details
- (Object) bar_mark=(value) (writeonly)
Sets the attribute bar_mark
36 37 38 |
# File 'lib/progressbar.rb', line 36 def (value) @bar_mark = value end |
- (Object) current (readonly)
Returns the value of attribute current
33 34 35 |
# File 'lib/progressbar.rb', line 33 def current @current end |
- (Object) start_time
Returns the value of attribute start_time
35 36 37 |
# File 'lib/progressbar.rb', line 35 def start_time @start_time end |
- (Object) title (readonly)
Returns the value of attribute title
32 33 34 |
# File 'lib/progressbar.rb', line 32 def title @title end |
- (Object) total (readonly)
Returns the value of attribute total
34 35 36 |
# File 'lib/progressbar.rb', line 34 def total @total end |
Instance Method Details
- (Object) clear
178 179 180 181 182 |
# File 'lib/progressbar.rb', line 178 def clear @out.print "\r" @out.print(" " * (get_width - 1)) @out.print "\r" end |
- (Object) file_transfer_mode
194 195 196 |
# File 'lib/progressbar.rb', line 194 def file_transfer_mode @format_arguments = [:title, :percentage, :bar, :stat_for_file_transfer] end |
- (Object) finish
184 185 186 187 188 |
# File 'lib/progressbar.rb', line 184 def finish @current = @total @finished_p = true show end |
- (Boolean) finished?
190 191 192 |
# File 'lib/progressbar.rb', line 190 def finished? @finished_p end |
- (Object) format=(format)
198 199 200 |
# File 'lib/progressbar.rb', line 198 def format= (format) @format = format end |
- (Object) format_arguments=(arguments)
202 203 204 |
# File 'lib/progressbar.rb', line 202 def format_arguments= (arguments) @format_arguments = arguments end |
- (Object) halt
206 207 208 209 |
# File 'lib/progressbar.rb', line 206 def halt @finished_p = true show end |
- (Object) inc(step = 1)
211 212 213 214 215 216 |
# File 'lib/progressbar.rb', line 211 def inc (step = 1) @current += step @current = @total if @current > @total show_if_needed @previous = @current end |
- (Object) inspect
227 228 229 |
# File 'lib/progressbar.rb', line 227 def inspect "#<ProgressBar:#{@current}/#{@total}>" end |
- (Object) set(count)
218 219 220 221 222 223 224 225 |
# File 'lib/progressbar.rb', line 218 def set (count) if count < 0 || count > @total raise "invalid count: #{count} (total: #{@total})" end @current = count show_if_needed @previous = @current end |