Class: Console::ProgressBar
Instance Method Summary collapse
- #bar_mark=(mark) ⇒ Object
- #file_transfer_mode ⇒ Object
- #finish ⇒ Object
- #flush ⇒ 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
- #title=(str) ⇒ Object
- #total_overflow=(boolv) ⇒ Object
Constructor Details
#initialize(title, total, out = STDERR) ⇒ ProgressBar
Returns a new instance of ProgressBar.
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/more/facets/progressbar.rb', line 37 def initialize(title, total, out = STDERR) @title = title @total = total @out = out = 80 = "o" @total_overflow = true @current = 0 @previous = 0 @is_finished = false @start_time = Time.now @format = "%-14s %3d%% %s %s" @format_arguments = [:title, :percentage, :bar, :stat] show_progress end |
Instance Method Details
#bar_mark=(mark) ⇒ Object
188 189 190 |
# File 'lib/more/facets/progressbar.rb', line 188 def (mark) = String(mark)[0..0] end |
#file_transfer_mode ⇒ Object
180 181 182 |
# File 'lib/more/facets/progressbar.rb', line 180 def file_transfer_mode @format_arguments = [:title, :percentage, :bar, :stat_for_file_transfer] end |
#finish ⇒ Object
204 205 206 207 208 |
# File 'lib/more/facets/progressbar.rb', line 204 def finish @current = @total @is_finished = true show_progress end |
#flush ⇒ Object
210 211 212 |
# File 'lib/more/facets/progressbar.rb', line 210 def flush @out.flush end |
#format=(format) ⇒ Object
196 197 198 |
# File 'lib/more/facets/progressbar.rb', line 196 def format=(format) @format = format end |
#format_arguments=(arguments) ⇒ Object
200 201 202 |
# File 'lib/more/facets/progressbar.rb', line 200 def format_arguments=(arguments) @format_arguments = arguments end |
#halt ⇒ Object
214 215 216 217 |
# File 'lib/more/facets/progressbar.rb', line 214 def halt @is_finished = true show_progress end |
#inc(step = 1) ⇒ Object
234 235 236 237 238 239 |
# File 'lib/more/facets/progressbar.rb', line 234 def inc(step = 1) @current += step @current = @total if @current > @total show_progress @previous = @current end |
#inspect ⇒ Object
241 242 243 |
# File 'lib/more/facets/progressbar.rb', line 241 def inspect "(ProgressBar: #{@current}/#{@total})" end |
#set(count) ⇒ Object
219 220 221 222 223 224 225 226 227 228 229 230 231 232 |
# File 'lib/more/facets/progressbar.rb', line 219 def set(count) if count < 0 raise "invalid count less than zero: #{count}" elsif count > @total if @total_overflow @total = count + 1 else raise "invalid count greater than total: #{count}" end end @current = count show_progress @previous = @current end |
#title=(str) ⇒ Object
184 185 186 |
# File 'lib/more/facets/progressbar.rb', line 184 def title=(str) @title = str end |
#total_overflow=(boolv) ⇒ Object
192 193 194 |
# File 'lib/more/facets/progressbar.rb', line 192 def total_overflow=(boolv) @total_overflow = boolv ? true : false end |