Class: Mongify::ProgressBar
- Inherits:
-
Object
- Object
- Mongify::ProgressBar
- Defined in:
- lib/mongify/progressbar.rb
Overview
Progress bar used to display results
Direct Known Subclasses
Constant Summary collapse
- VERSION =
Progress bar version
"0.9.1"
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
Clear’s line.
-
#file_transfer_mode ⇒ Object
Sets bar to file trasfer mode.
-
#finish ⇒ Object
Marks finished.
-
#finished? ⇒ Boolean
Returns if the bar is finished.
-
#format=(format) ⇒ Object
Allows format to be re/defined.
-
#format_arguments=(arguments) ⇒ Object
Allows to change the arguments of items that are shown.
-
#halt ⇒ Object
halts drawing of bar.
-
#inc(step = 1) ⇒ Integer
Incremets bar.
-
#initialize(title, total, out = STDERR) ⇒ ProgressBar
constructor
A new instance of ProgressBar.
-
#inspect ⇒ Object
Returns string representation of this object.
-
#set(count) ⇒ Integer
Allows you to set bar frame.
Constructor Details
#initialize(title, total, out = STDERR) ⇒ ProgressBar
Returns a new instance of ProgressBar.
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/mongify/progressbar.rb', line 22 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 = 35 @format = "%-#{@title_width}s %s %3d%% %s %s" @format_arguments = [:title, :count, :percentage, :bar, :stat] clear show end |
Instance Attribute Details
#current ⇒ Object (readonly)
Returns the value of attribute current.
40 41 42 |
# File 'lib/mongify/progressbar.rb', line 40 def current @current end |
#start_time ⇒ Object
Returns the value of attribute start_time.
42 43 44 |
# File 'lib/mongify/progressbar.rb', line 42 def start_time @start_time end |
#title ⇒ Object (readonly)
Returns the value of attribute title.
39 40 41 |
# File 'lib/mongify/progressbar.rb', line 39 def title @title end |
#total ⇒ Object (readonly)
Returns the value of attribute total.
41 42 43 |
# File 'lib/mongify/progressbar.rb', line 41 def total @total end |
Instance Method Details
#clear ⇒ Object
Clear’s line
198 199 200 201 202 |
# File 'lib/mongify/progressbar.rb', line 198 def clear @out.print "\r" @out.print(" " * (get_width - 1)) @out.print "\r" end |
#file_transfer_mode ⇒ Object
Sets bar to file trasfer mode
217 218 219 |
# File 'lib/mongify/progressbar.rb', line 217 def file_transfer_mode @format_arguments = [:title, :percentage, :bar, :stat_for_file_transfer] end |
#finish ⇒ Object
Marks finished
205 206 207 208 209 |
# File 'lib/mongify/progressbar.rb', line 205 def finish @current = @total @finished_p = true show end |
#finished? ⇒ Boolean
Returns if the bar is finished
212 213 214 |
# File 'lib/mongify/progressbar.rb', line 212 def finished? @finished_p end |
#format=(format) ⇒ Object
Allows format to be re/defined
222 223 224 |
# File 'lib/mongify/progressbar.rb', line 222 def format= (format) @format = format end |
#format_arguments=(arguments) ⇒ Object
Allows to change the arguments of items that are shown
227 228 229 |
# File 'lib/mongify/progressbar.rb', line 227 def format_arguments= (arguments) @format_arguments = arguments end |
#halt ⇒ Object
halts drawing of bar
232 233 234 235 |
# File 'lib/mongify/progressbar.rb', line 232 def halt @finished_p = true show end |
#inc(step = 1) ⇒ Integer
Incremets bar
239 240 241 242 243 244 |
# File 'lib/mongify/progressbar.rb', line 239 def inc (step = 1) @current += step @current = @total if @current > @total show_if_needed @previous = @current end |
#inspect ⇒ Object
Returns string representation of this object
258 259 260 |
# File 'lib/mongify/progressbar.rb', line 258 def inspect "#<ProgressBar:#{@current}/#{@total}>" end |
#set(count) ⇒ Integer
Allows you to set bar frame
248 249 250 251 252 253 254 255 |
# File 'lib/mongify/progressbar.rb', line 248 def set (count) if count < 0 || count > @total raise "invalid count: #{count} (total: #{@total})" end @current = count show_if_needed @previous = @current end |