Class: Luck::ProgressBar

Inherits:
Control show all
Defined in:
lib/luck/progressbar.rb

Direct Known Subclasses

DoubleProgressBar

Instance Attribute Summary collapse

Attributes inherited from Control

#display, #pane, #x1, #x2, #y1, #y2

Instance Method Summary collapse

Methods inherited from Control

#focus!, #height, #width

Constructor Details

#initialize(*args) ⇒ ProgressBar

Returns a new instance of ProgressBar.



5
6
7
8
9
10
11
12
13
14
# File 'lib/luck/progressbar.rb', line 5

def initialize *args
  @maximum = 1
  @value = 0
  @precap = '['
  @bar = '='
  @arrow = '>'
  @blank = ' '
  @postcap = ']'
  super
end

Instance Attribute Details

#arrowObject

Returns the value of attribute arrow.



3
4
5
# File 'lib/luck/progressbar.rb', line 3

def arrow
  @arrow
end

#barObject

Returns the value of attribute bar.



3
4
5
# File 'lib/luck/progressbar.rb', line 3

def bar
  @bar
end

#blankObject

Returns the value of attribute blank.



3
4
5
# File 'lib/luck/progressbar.rb', line 3

def blank
  @blank
end

#maximumObject

Returns the value of attribute maximum.



3
4
5
# File 'lib/luck/progressbar.rb', line 3

def maximum
  @maximum
end

#postcapObject

Returns the value of attribute postcap.



3
4
5
# File 'lib/luck/progressbar.rb', line 3

def postcap
  @postcap
end

#precapObject

Returns the value of attribute precap.



3
4
5
# File 'lib/luck/progressbar.rb', line 3

def precap
  @precap
end

#valueObject

Returns the value of attribute value.



3
4
5
# File 'lib/luck/progressbar.rb', line 3

def value
  @value
end

Instance Method Details

#percentageObject



16
17
18
# File 'lib/luck/progressbar.rb', line 16

def percentage
  @value.to_f / @maximum.to_f
end

#redrawObject



24
25
26
# File 'lib/luck/progressbar.rb', line 24

def redraw
  @display.place y1, x1, @precap + (@bar * (percentage * (width - @precap.size - @postcap.size)) + @arrow).ljust(width - @precap.size - @postcap.size, @blank) + @postcap
end

#template(str) ⇒ Object



20
21
22
# File 'lib/luck/progressbar.rb', line 20

def template str
  @precap, @bar, @arrow, @blank, @postcap = str.unpack 'aaaaa'
end