Class: Archive::Tar::Minitar::Command::ProgressBar
- Inherits:
-
Object
- Object
- Archive::Tar::Minitar::Command::ProgressBar
- Defined in:
- lib/archive/tar/minitar/command.rb
Constant Summary collapse
- VERSION =
"0.8"
Instance Attribute Summary collapse
-
#title ⇒ Object
writeonly
Sets the attribute title.
-
#total ⇒ Object
Returns the value of attribute total.
Instance Method Summary collapse
- #file_transfer_mode ⇒ Object
- #finish ⇒ Object
- #format=(format) ⇒ Object
- #format_arguments=(arguments) ⇒ Object
- #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.
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/archive/tar/minitar/command.rb', line 35 def initialize (title, total, out = STDERR) @title = title @total = total @out = out @bar_width = 80 @bar_mark = "o" @current = 0 @previous = 0 @is_finished = 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] show end |
Instance Attribute Details
#title=(value) ⇒ Object
Sets the attribute title
33 34 35 |
# File 'lib/archive/tar/minitar/command.rb', line 33 def title=(value) @title = value end |
#total ⇒ Object
Returns the value of attribute total.
32 33 34 |
# File 'lib/archive/tar/minitar/command.rb', line 32 def total @total end |
Instance Method Details
#file_transfer_mode ⇒ Object
182 183 184 |
# File 'lib/archive/tar/minitar/command.rb', line 182 def file_transfer_mode @format_arguments = [:title, :percentage, :bar, :stat_for_file_transfer] end |
#finish ⇒ Object
194 195 196 197 198 |
# File 'lib/archive/tar/minitar/command.rb', line 194 def finish @current = @total @is_finished = true show_progress end |
#format=(format) ⇒ Object
186 187 188 |
# File 'lib/archive/tar/minitar/command.rb', line 186 def format= (format) @format = format end |
#format_arguments=(arguments) ⇒ Object
190 191 192 |
# File 'lib/archive/tar/minitar/command.rb', line 190 def format_arguments= (arguments) @format_arguments = arguments end |
#halt ⇒ Object
200 201 202 203 |
# File 'lib/archive/tar/minitar/command.rb', line 200 def halt @is_finished = true show_progress end |
#inc(step = 1) ⇒ Object
214 215 216 217 218 219 |
# File 'lib/archive/tar/minitar/command.rb', line 214 def inc (step = 1) @current += step @current = @total if @current > @total show_progress @previous = @current end |
#inspect ⇒ Object
221 222 223 |
# File 'lib/archive/tar/minitar/command.rb', line 221 def inspect "(ProgressBar: #{@current}/#{@total})" end |
#set(count) ⇒ Object
205 206 207 208 209 210 211 212 |
# File 'lib/archive/tar/minitar/command.rb', line 205 def set (count) if count < 0 || count > @total raise "invalid count: #{count} (total: #{@total})" end @current = count show_progress @previous = @current end |