Class: Tqdm::Printer::DefaultFormat
- Inherits:
-
Object
- Object
- Tqdm::Printer::DefaultFormat
- Defined in:
- lib/tqdm/printer/default_format.rb
Constant Summary collapse
- PROGRESS_BAR_WIDTH =
10- SPACE =
'-'- PROGRESS =
'#'
Instance Method Summary collapse
-
#initialize(options) ⇒ DefaultFormat
constructor
Initialize a new DefaultFormat.
-
#line(iteration, elapsed_time) ⇒ String
Formats the prefix, progress bar and meter as a complete line to be printed.
-
#meter(n, total, elapsed) ⇒ String
Formats a count (n) of total items processed + an elapsed time into a textual progress bar + meter.
Constructor Details
#initialize(options) ⇒ DefaultFormat
Initialize a new DefaultFormat.
13 14 15 16 |
# File 'lib/tqdm/printer/default_format.rb', line 13 def initialize() @total = [:total] @prefix = [:desc] ? [:desc] + ': ' : '' end |
Instance Method Details
#line(iteration, elapsed_time) ⇒ String
Formats the prefix, progress bar and meter as a complete line to be printed
25 26 27 |
# File 'lib/tqdm/printer/default_format.rb', line 25 def line(iteration, elapsed_time) prefix + meter(iteration, total, elapsed_time) end |
#meter(n, total, elapsed) ⇒ String
Formats a count (n) of total items processed + an elapsed time into a textual progress bar + meter.
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/tqdm/printer/default_format.rb', line 36 def meter(n, total, elapsed) total = (n > total ? nil : total) if total elapsed_str = interval(elapsed) rate = elapsed && elapsed > 0 ? ('%5.2f' % (n / elapsed)) : '?' if total && total > 0 frac = n.to_f / total = (frac * PROGRESS_BAR_WIDTH).to_i = PROGRESS * + SPACE * (PROGRESS_BAR_WIDTH - ) percentage = '%3d%%' % (frac * 100) left_str = n > 0 ? (interval(elapsed / n * (total - n))) : '?' '|%s| %d/%d %s [elapsed: %s left: %s, %s iters/sec]' % [, n, total, percentage, elapsed_str, left_str, rate] else '%d [elapsed: %s, %s iters/sec]' % [n, elapsed_str, rate] end end |