Sha256: ec87b892031e8e813af6649689923fa01a6b7c08f0bd88936bbb4f0d165e1a6a

Contents?: true

Size: 474 Bytes

Versions: 7

Compression:

Stored size: 474 Bytes

Contents

class ProgressBar
  class Bar < Meter

    attr_reader :count, :max, :width

    def initialize(count, max, width)
      @count, @max, @width = count, max, width
    end

    def to_s
      "[" +
        "#" * progress_width +
        " " * remaining_width +
      "]"
    end

    def bar_width
      width - 2
    end

    def progress_width
      ((count.to_f / max) * bar_width).ceil
    end

    def remaining_width
      bar_width - progress_width
    end

  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
progress_bar-0.3.4 lib/progress_bar/meters/bar.rb
progress_bar-0.3.3 lib/progress_bar/meters/bar.rb
progress_bar-0.3.2 lib/progress_bar/meters/bar.rb
progress_bar-0.3.1 lib/progress_bar/meters/bar.rb
progress_bar-0.3.0 lib/progress_bar/meters/bar.rb
progress_bar-0.2.0 lib/progress_bar/meters/bar.rb
progress_bar-0.1.0 lib/progress_bar/meters/bar.rb