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) ⇒ 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) ⇒ 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) @title = title @total = total @out = Mongify::Configuration.out_stream @terminal_width = 80 @bar_mark = "o" @current = 0 @previous = 0 @finished_p = false @start_time = Time.now @previous_time = @start_time @title_width = 37 @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
199 200 201 202 203 204 |
# File 'lib/mongify/progressbar.rb', line 199 def clear return unless @out @out.print "\r" @out.print(" " * (get_width - 1)) @out.print "\r" end |
#file_transfer_mode ⇒ Object
Sets bar to file trasfer mode
219 220 221 |
# File 'lib/mongify/progressbar.rb', line 219 def file_transfer_mode @format_arguments = [:title, :percentage, :bar, :stat_for_file_transfer] end |
#finish ⇒ Object
Marks finished
207 208 209 210 211 |
# File 'lib/mongify/progressbar.rb', line 207 def finish @current = @total @finished_p = true show end |
#finished? ⇒ Boolean
Returns if the bar is finished
214 215 216 |
# File 'lib/mongify/progressbar.rb', line 214 def finished? @finished_p end |
#format=(format) ⇒ Object
Allows format to be re/defined
224 225 226 |
# File 'lib/mongify/progressbar.rb', line 224 def format= (format) @format = format end |
#format_arguments=(arguments) ⇒ Object
Allows to change the arguments of items that are shown
229 230 231 |
# File 'lib/mongify/progressbar.rb', line 229 def format_arguments= (arguments) @format_arguments = arguments end |
#halt ⇒ Object
halts drawing of bar
234 235 236 237 |
# File 'lib/mongify/progressbar.rb', line 234 def halt @finished_p = true show end |
#inc(step = 1) ⇒ Integer
Incremets bar
241 242 243 244 245 246 |
# File 'lib/mongify/progressbar.rb', line 241 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
260 261 262 |
# File 'lib/mongify/progressbar.rb', line 260 def inspect "#<ProgressBar:#{@current}/#{@total}>" end |
#set(count) ⇒ Integer
Allows you to set bar frame
250 251 252 253 254 255 256 257 |
# File 'lib/mongify/progressbar.rb', line 250 def set (count) if count < 0 || count > @total raise "invalid count: #{count} (total: #{@total})" end @current = count show_if_needed @previous = @current end |