Sha256: 5ec1a5549ebeaa8728275c036179f5bd90d5a1bdf4e40ecc0b44cad3e94119d4

Contents?: true

Size: 867 Bytes

Versions: 15

Compression:

Stored size: 867 Bytes

Contents

module Traquitana
   class Bar
      attr_reader :current
      attr_accessor :name, :total

      def initialize
         reset
      end      

      def reset
         @name       = nil
         @total      = 0
         @current    = 0
         @bar_size   = 20
         @bar_step   = 5
      end

      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

      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
   end
end

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
traquitana-0.0.26 lib/bar.rb
traquitana-0.0.25 lib/bar.rb
traquitana-0.0.24 lib/bar.rb
traquitana-0.0.23 lib/bar.rb
traquitana-0.0.22 lib/bar.rb
traquitana-0.0.21 lib/bar.rb
traquitana-0.0.20 lib/bar.rb
traquitana-0.0.19 lib/bar.rb
traquitana-0.0.18 lib/bar.rb
traquitana-0.0.17 lib/bar.rb
traquitana-0.0.16 lib/bar.rb
traquitana-0.0.15 lib/bar.rb
traquitana-0.0.14 lib/bar.rb
traquitana-0.0.13 lib/bar.rb
traquitana-0.0.12 lib/bar.rb