Method: ProgressBar#output

Defined in:
lib/progressbar.rb,
lib/web/progressbar4web.rb

#output(num) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/progressbar.rb', line 17

def output(num)
  return if $debug
  if num > @max
    raise OverRangeError, "`#{num}` over `#{@max}(max)`"
  end
  @counter += 1
  return unless @counter % @interval == 0
  ratio = calc_ratio(num)
  now = (@width * ratio).round
  rest = @width - now
  STDOUT.print "[" + @char * now + ' ' * rest + "] #{(ratio * 100).round}%\r"
end