Class: Luck::ProgressBar
Direct Known Subclasses
Instance Attribute Summary collapse
-
#arrow ⇒ Object
Returns the value of attribute arrow.
-
#bar ⇒ Object
Returns the value of attribute bar.
-
#blank ⇒ Object
Returns the value of attribute blank.
-
#maximum ⇒ Object
Returns the value of attribute maximum.
-
#postcap ⇒ Object
Returns the value of attribute postcap.
-
#precap ⇒ Object
Returns the value of attribute precap.
-
#value ⇒ Object
Returns the value of attribute value.
Attributes inherited from Control
#display, #pane, #x1, #x2, #y1, #y2
Instance Method Summary collapse
-
#initialize(*args) ⇒ ProgressBar
constructor
A new instance of ProgressBar.
- #percentage ⇒ Object
- #redraw ⇒ Object
- #template(str) ⇒ Object
Methods inherited from Control
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
#arrow ⇒ Object
Returns the value of attribute arrow.
3 4 5 |
# File 'lib/luck/progressbar.rb', line 3 def arrow @arrow end |
#bar ⇒ Object
Returns the value of attribute bar.
3 4 5 |
# File 'lib/luck/progressbar.rb', line 3 def @bar end |
#blank ⇒ Object
Returns the value of attribute blank.
3 4 5 |
# File 'lib/luck/progressbar.rb', line 3 def blank @blank end |
#maximum ⇒ Object
Returns the value of attribute maximum.
3 4 5 |
# File 'lib/luck/progressbar.rb', line 3 def maximum @maximum end |
#postcap ⇒ Object
Returns the value of attribute postcap.
3 4 5 |
# File 'lib/luck/progressbar.rb', line 3 def postcap @postcap end |
#precap ⇒ Object
Returns the value of attribute precap.
3 4 5 |
# File 'lib/luck/progressbar.rb', line 3 def precap @precap end |
#value ⇒ Object
Returns the value of attribute value.
3 4 5 |
# File 'lib/luck/progressbar.rb', line 3 def value @value end |
Instance Method Details
#percentage ⇒ Object
16 17 18 |
# File 'lib/luck/progressbar.rb', line 16 def percentage @value.to_f / @maximum.to_f end |
#redraw ⇒ Object
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 |