class Console::Event::Progress

Constants

BLOCK

Attributes

current[R]
total[R]

Public Class Methods

new(current, total) click to toggle source
# File lib/console/event/progress.rb, line 38
def initialize(current, total)
        @current = current
        @total = total
end
register(terminal) click to toggle source
# File lib/console/event/progress.rb, line 62
def self.register(terminal)
        terminal[:progress_bar] ||= terminal.style(:blue, :white)
end

Public Instance Methods

bar(value = self.value, width = 70) click to toggle source
# File lib/console/event/progress.rb, line 50
def bar(value = self.value, width = 70)
        blocks = width * value
        full_blocks = blocks.floor
        partial_block = ((blocks - full_blocks) * BLOCK.size).floor
        
        if partial_block.zero?
                BLOCK.last * full_blocks
        else
                "#{BLOCK.last * full_blocks}#{BLOCK[partial_block]}"
        end.ljust(width)
end
format(output, terminal, verbose) click to toggle source
# File lib/console/event/progress.rb, line 70
def format(output, terminal, verbose)
        output.puts "#{terminal[:progress_bar]}#{self.bar}#{terminal.reset} #{sprintf('%6.2f', self.value * 100)}%"
end
to_h() click to toggle source
# File lib/console/event/progress.rb, line 66
def to_h
        {current: @current, total: @total}
end
value() click to toggle source
# File lib/console/event/progress.rb, line 46
def value
        @current.to_f / @total.to_f
end