Class: Console::Terminal::Formatter::Progress

Inherits:
Object
  • Object
show all
Defined in:
lib/console/terminal/formatter/progress.rb

Constant Summary collapse

KEY =
:progress
BLOCK =
[
	" ",
	"",
	"",
	"",
	"",
	"",
	"",
	"",
	"",
]

Instance Method Summary collapse

Constructor Details

#initialize(terminal) ⇒ Progress

Returns a new instance of Progress.



24
25
26
27
# File 'lib/console/terminal/formatter/progress.rb', line 24

def initialize(terminal)
	@terminal = terminal
	@terminal[:progress_bar] ||= terminal.style(:blue, :white)
end

Instance Method Details

#format(event, output, verbose: false, width: 80) ⇒ Object



29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/console/terminal/formatter/progress.rb', line 29

def format(event, output, verbose: false, width: 80)
	current = event[:current].to_f
	total = event[:total].to_f
	value = current / total
	
	# Clamp value to 1.0 to avoid rendering issues:
	if value > 1.0
		value = 1.0
	end
	
	output.puts "#{@terminal[:progress_bar]}#{self.bar(value, width-10)}#{@terminal.reset} #{sprintf('%6.2f', value * 100)}%"
end