Class: Sus::Output::Bar
- Inherits:
-
Object
- Object
- Sus::Output::Bar
- Defined in:
- lib/sus/output/bar.rb
Constant Summary collapse
- BLOCK =
[ " ", "▏", "▎", "▍", "▌", "▋", "▊", "▉", "█", ]
- MINIMUM_WIDTH =
8
- MESSAGE_SUFFIX =
": "
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(current = 0, total = 0, message = nil) ⇒ Bar
constructor
A new instance of Bar.
- #print(output) ⇒ Object
- #update(current, total, message) ⇒ Object
Constructor Details
#initialize(current = 0, total = 0, message = nil) ⇒ Bar
Returns a new instance of Bar.
21 22 23 24 25 26 27 |
# File 'lib/sus/output/bar.rb', line 21 def initialize(current = 0, total = 0, = nil) @maximum_message_width = 0 @current = current @total = total @message = end |
Class Method Details
.register(output) ⇒ Object
35 36 37 |
# File 'lib/sus/output/bar.rb', line 35 def self.register(output) output[:progress_bar] ||= output.style(:blue, :white) end |
Instance Method Details
#print(output) ⇒ Object
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/sus/output/bar.rb', line 42 def print(output) width = output.width unless @total.zero? value = @current.to_f / @total.to_f else value = 0.0 end if @message = @message + MESSAGE_SUFFIX if .size > @maximum_message_width @maximum_message_width = .size end if @maximum_message_width < (width - MINIMUM_WIDTH) width -= @maximum_message_width = .rjust(@maximum_message_width) else @maximum_message_width = 0 = nil end end if output.write() end output.write( :progress_bar, draw(value, width), :reset, ) output.puts end |
#update(current, total, message) ⇒ Object
29 30 31 32 33 |
# File 'lib/sus/output/bar.rb', line 29 def update(current, total, ) @current = current @total = total @message = end |