Class: Chronicle::ETL::Utils::ProgressBar
- Inherits:
-
Object
- Object
- Chronicle::ETL::Utils::ProgressBar
- Defined in:
- lib/chronicle/etl/utils/progress_bar.rb
Constant Summary collapse
- FORMAT_WITH_TOTAL =
[ ':bar ', ':percent'.light_white, ' | '.light_black, ':current'.light_white, '/'.light_black, ':total'.light_white, ' ('.light_black, 'ELAPSED:'.light_black, ':elapsed'.light_white, ' | ETA:'.light_black, ':eta'.light_white, ' | RATE: '.light_black, ':mean_rate'.light_white, '/s) '.light_black ].join.freeze
- FORMAT_WITHOUT_TOTAL =
[ ':current'.light_white, '/'.light_black, '???'.light_white, ' ('.light_black, 'ELAPSED:'.light_black, ':elapsed'.light_white, ' | ETA:'.light_black, '??:??'.light_white, ' | RATE: '.light_black, ':mean_rate'.light_white, '/s) '.light_black ].join.freeze
Instance Method Summary collapse
- #finish ⇒ Object
- #increment ⇒ Object
-
#initialize(total:, title: 'Loading') ⇒ ProgressBar
constructor
A new instance of ProgressBar.
- #log(message) ⇒ Object
Constructor Details
#initialize(total:, title: 'Loading') ⇒ ProgressBar
Returns a new instance of ProgressBar.
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/chronicle/etl/utils/progress_bar.rb', line 39 def initialize(total:, title: 'Loading') opts = { clear: true, complete: '▓'.light_blue, incomplete: '░'.blue, frequency: 10 } if total opts[:total] = total format_str = "#{title} #{FORMAT_WITH_TOTAL}" @pbar = TTY::ProgressBar.new(FORMAT_WITH_TOTAL, opts) else format_str = "#{title} #{FORMAT_WITHOUT_TOTAL}" opts[:no_width] = true end @pbar = TTY::ProgressBar.new(format_str, opts) @pbar.resize end |
Instance Method Details
#finish ⇒ Object
71 72 73 |
# File 'lib/chronicle/etl/utils/progress_bar.rb', line 71 def finish @pbar.finish end |
#increment ⇒ Object
61 62 63 |
# File 'lib/chronicle/etl/utils/progress_bar.rb', line 61 def increment @pbar.advance(1) end |
#log(message) ⇒ Object
65 66 67 68 69 |
# File 'lib/chronicle/etl/utils/progress_bar.rb', line 65 def log() .split("\n").each do |_line| @pbar.log end end |