Class: ProgressBar::Bar

Inherits:
Meter
  • Object
show all
Defined in:
lib/progress_bar/meters/bar.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(count, max, width) ⇒ Bar

Returns a new instance of Bar.



7
8
9
# File 'lib/progress_bar/meters/bar.rb', line 7

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

Instance Attribute Details

#countObject (readonly)

Returns the value of attribute count.



5
6
7
# File 'lib/progress_bar/meters/bar.rb', line 5

def count
  @count
end

#maxObject (readonly)

Returns the value of attribute max.



5
6
7
# File 'lib/progress_bar/meters/bar.rb', line 5

def max
  @max
end

#widthObject (readonly)

Returns the value of attribute width.



5
6
7
# File 'lib/progress_bar/meters/bar.rb', line 5

def width
  @width
end

Instance Method Details

#bar_widthObject



18
19
20
# File 'lib/progress_bar/meters/bar.rb', line 18

def bar_width
  width - 2
end

#progress_widthObject



22
23
24
# File 'lib/progress_bar/meters/bar.rb', line 22

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

#remaining_widthObject



26
27
28
# File 'lib/progress_bar/meters/bar.rb', line 26

def remaining_width
  bar_width - progress_width
end

#to_sObject



11
12
13
14
15
16
# File 'lib/progress_bar/meters/bar.rb', line 11

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