Class: ProgressBar
- Inherits:
-
Object
- Object
- ProgressBar
- Defined in:
- lib/taps/progress_bar.rb
Overview
Ruby/ProgressBar - a text progress bar library
Copyright © 2001-2005 Satoru Takabayashi <[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.9'.freeze
Instance Attribute Summary collapse
-
#current ⇒ Object
readonly
Returns the value of attribute current.
-
#format ⇒ Object
writeonly
Sets the attribute format.
-
#format_arguments ⇒ Object
writeonly
Sets the attribute format_arguments.
-
#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
- #halt ⇒ Object
- #inc(step = 1) ⇒ Object
-
#initialize(title, total, out = STDERR) ⇒ ProgressBar
constructor
A new instance of ProgressBar.
- #inspect ⇒ Object
- #set(count) ⇒ Object
Constructor Details
#initialize(title, total, out = STDERR) ⇒ ProgressBar
Returns a new instance of ProgressBar.
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/taps/progress_bar.rb', line 15 def initialize(title, total, 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 = 14 @format = "%-#{@title_width}s %3d%% %s %s" @format_arguments = %i[title percentage bar stat] clear show end |
Instance Attribute Details
#current ⇒ Object (readonly)
Returns the value of attribute current.
33 34 35 |
# File 'lib/taps/progress_bar.rb', line 33 def current @current end |
#format=(value) ⇒ Object (writeonly)
Sets the attribute format
200 201 202 |
# File 'lib/taps/progress_bar.rb', line 200 def format=(value) @format = value end |
#format_arguments=(value) ⇒ Object (writeonly)
Sets the attribute format_arguments
202 203 204 |
# File 'lib/taps/progress_bar.rb', line 202 def format_arguments=(value) @format_arguments = value end |
#start_time ⇒ Object
Returns the value of attribute start_time.
35 36 37 |
# File 'lib/taps/progress_bar.rb', line 35 def start_time @start_time end |
#title ⇒ Object (readonly)
Returns the value of attribute title.
32 33 34 |
# File 'lib/taps/progress_bar.rb', line 32 def title @title end |
#total ⇒ Object (readonly)
Returns the value of attribute total.
34 35 36 |
# File 'lib/taps/progress_bar.rb', line 34 def total @total end |
Instance Method Details
#clear ⇒ Object
180 181 182 183 184 |
# File 'lib/taps/progress_bar.rb', line 180 def clear @out.print "\r" @out.print(' ' * (get_width - 1)) @out.print "\r" end |
#file_transfer_mode ⇒ Object
196 197 198 |
# File 'lib/taps/progress_bar.rb', line 196 def file_transfer_mode @format_arguments = %i[title percentage bar stat_for_file_transfer] end |
#finish ⇒ Object
186 187 188 189 190 |
# File 'lib/taps/progress_bar.rb', line 186 def finish @current = @total @finished_p = true show end |
#finished? ⇒ Boolean
192 193 194 |
# File 'lib/taps/progress_bar.rb', line 192 def finished? @finished_p end |
#halt ⇒ Object
204 205 206 207 |
# File 'lib/taps/progress_bar.rb', line 204 def halt @finished_p = true show end |
#inc(step = 1) ⇒ Object
209 210 211 212 213 214 |
# File 'lib/taps/progress_bar.rb', line 209 def inc(step = 1) @current += step @current = @total if @current > @total show_if_needed @previous = @current end |
#inspect ⇒ Object
225 226 227 |
# File 'lib/taps/progress_bar.rb', line 225 def inspect "#<ProgressBar:#{@current}/#{@total}>" end |
#set(count) ⇒ Object
216 217 218 219 220 221 222 223 |
# File 'lib/taps/progress_bar.rb', line 216 def set(count) if count < 0 || count > @total raise "invalid count: #{count} (total: #{@total})" end @current = count show_if_needed @previous = @current end |