Class: ProgressWidget
- Inherits:
-
Object
- Object
- ProgressWidget
- Defined in:
- lib/delve/widgets/progress.rb
Instance Attribute Summary collapse
-
#current ⇒ Object
Returns the value of attribute current.
-
#max ⇒ Object
Returns the value of attribute max.
Instance Method Summary collapse
- #draw(display) ⇒ Object
-
#initialize(x, y, width, current, max, fg, bg) ⇒ ProgressWidget
constructor
A new instance of ProgressWidget.
Constructor Details
#initialize(x, y, width, current, max, fg, bg) ⇒ ProgressWidget
Returns a new instance of ProgressWidget.
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/delve/widgets/progress.rb', line 4 def initialize(x, y, width, current, max, fg, bg) raise 'Cannot initialize progress widget when x is nil' unless x raise 'Cannot initialize progress widget when y is nil' unless y raise 'Cannot initialize progress widget when width is nil' unless width raise 'Cannot initialize progress widget when current value is nil' unless current raise 'Cannot initialize progress widget when max value is nil' unless max raise 'Cannot initialize progress widget when foreground color is nil' unless fg raise 'Cannot initialize progress widget when background color is nil' unless bg @x = x @y = y @width = width @current = current @max = max @fg = fg @bg = bg end |
Instance Attribute Details
#current ⇒ Object
Returns the value of attribute current.
2 3 4 |
# File 'lib/delve/widgets/progress.rb', line 2 def current @current end |
#max ⇒ Object
Returns the value of attribute max.
2 3 4 |
# File 'lib/delve/widgets/progress.rb', line 2 def max @max end |
Instance Method Details
#draw(display) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/delve/widgets/progress.rb', line 22 def draw(display) raise 'Cannot draw text when display is nil' unless display percent = 1.0 * @current / @max to_fill = (percent * @width).ceil x = @x (0..@width-1).each do |i| color = i < to_fill ? @fg : @bg display.draw x, @y, ' ', color, color x += 1 end end |