Sha256: 6b9ea792e8fb66085420312fd323cc5fad7341185783cbccfb44a707b8367525

Contents?: true

Size: 704 Bytes

Versions: 16

Compression:

Stored size: 704 Bytes

Contents

# -*- coding: utf-8 -*-
#
# Copyright 2013 whiteleaf. All rights reserved.
#

class ProgressBar
  def initialize(max, interval = 1, width = 50, char = "*")
    @max = max == 0 ? 1.0 : max.to_f
    @interval = interval
    @width = width
    @char = char
    @counter = 0
  end

  def output(num)
    return if $debug
    @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

  def clear
    return if $debug
    STDOUT.print " " * 79 + "\r"
  end

  def calc_ratio(num)
    num / @max
  end
end

Version data entries

16 entries across 16 versions & 1 rubygems

Version Path
narou-1.2.9 lib/progressbar.rb
narou-1.2.9.rc1 lib/progressbar.rb
narou-1.2.8 lib/progressbar.rb
narou-1.2.7 lib/progressbar.rb
narou-1.2.6 lib/progressbar.rb
narou-1.2.5.1 lib/progressbar.rb
narou-1.2.5 lib/progressbar.rb
narou-1.2.5.rc2 lib/progressbar.rb
narou-1.2.5.rc1 lib/progressbar.rb
narou-1.2.4 lib/progressbar.rb
narou-1.2.3 lib/progressbar.rb
narou-1.2.2 lib/progressbar.rb
narou-1.2.1 lib/progressbar.rb
narou-1.2.0 lib/progressbar.rb
narou-1.1.2.1 lib/progressbar.rb
narou-1.1.2 lib/progressbar.rb