class Traquitana::Bar

Attributes

current[R]
name[RW]
total[RW]

Public Class Methods

new() click to toggle source
# File lib/bar.rb, line 6
def initialize
  reset
end

Public Instance Methods

indicator(current) click to toggle source
# File lib/bar.rb, line 18
def indicator(current)
  bar = Array.new(@bar_size, "_")
  return bar.join if current <= 0

  prop = current > 0 ? ((100 / (total / current.to_f)) / @bar_step).to_i : 0
  return bar.join if prop <= 0

  bar[0...prop] = Array.new(prop, "#")
  bar.join
end
reset() click to toggle source
# File lib/bar.rb, line 10
def reset
  @name     = nil
  @total    = 0
  @current  = 0
  @bar_size = 20
  @bar_step = 5
end
update(current) click to toggle source
# File lib/bar.rb, line 29
def update(current)
  @current = current
  file     = File.basename(@name).ljust(25)
  STDOUT.print "#{file} : #{self.indicator(current)}\r"

  if @current >= @total
    STDOUT.puts "\n"
    @current = -1
  end
end