Class: Charming::Presentation::Components::Progressbar
- Inherits:
-
Charming::Presentation::Component
- Object
- View
- Charming::Presentation::Component
- Charming::Presentation::Components::Progressbar
- Defined in:
- lib/charming/presentation/components/progressbar.rb
Instance Attribute Summary collapse
-
#bar_format ⇒ Object
Returns the value of attribute bar_format.
-
#complete ⇒ Object
Returns the value of attribute complete.
-
#current ⇒ Object
Returns the value of attribute current.
-
#incomplete ⇒ Object
Returns the value of attribute incomplete.
-
#label ⇒ Object
Returns the value of attribute label.
-
#total ⇒ Object
Returns the value of attribute total.
Instance Method Summary collapse
- #complete! ⇒ Object
-
#initialize(total:, complete: "=", incomplete: " ", bar_format: :classic, label: nil) ⇒ Progressbar
constructor
A new instance of Progressbar.
- #render ⇒ Object
- #tick(count = 1) ⇒ Object
- #update(value) ⇒ Object
Methods inherited from View
Constructor Details
#initialize(total:, complete: "=", incomplete: " ", bar_format: :classic, label: nil) ⇒ Progressbar
Returns a new instance of Progressbar.
9 10 11 12 13 14 15 16 17 |
# File 'lib/charming/presentation/components/progressbar.rb', line 9 def initialize(total:, complete: "=", incomplete: " ", bar_format: :classic, label: nil) super() @total = [total.to_i, 0].max @complete = complete.to_s @incomplete = incomplete.to_s @bar_format = .to_sym @label = label @current = 0 end |
Instance Attribute Details
#bar_format ⇒ Object
Returns the value of attribute bar_format.
7 8 9 |
# File 'lib/charming/presentation/components/progressbar.rb', line 7 def @bar_format end |
#complete ⇒ Object
Returns the value of attribute complete.
7 8 9 |
# File 'lib/charming/presentation/components/progressbar.rb', line 7 def complete @complete end |
#current ⇒ Object
Returns the value of attribute current.
7 8 9 |
# File 'lib/charming/presentation/components/progressbar.rb', line 7 def current @current end |
#incomplete ⇒ Object
Returns the value of attribute incomplete.
7 8 9 |
# File 'lib/charming/presentation/components/progressbar.rb', line 7 def incomplete @incomplete end |
#label ⇒ Object
Returns the value of attribute label.
7 8 9 |
# File 'lib/charming/presentation/components/progressbar.rb', line 7 def label @label end |
#total ⇒ Object
Returns the value of attribute total.
7 8 9 |
# File 'lib/charming/presentation/components/progressbar.rb', line 7 def total @total end |
Instance Method Details
#complete! ⇒ Object
29 30 31 32 |
# File 'lib/charming/presentation/components/progressbar.rb', line 29 def complete! @current = @total self end |
#render ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/charming/presentation/components/progressbar.rb', line 34 def render width = [@total, 1].max completed = completed_width(width) incomplete = width - completed incomplete -= 1 if @current.zero? = (@complete * completed) + (@incomplete * incomplete) result = "[" + + "]" return result unless @label "#{result} #{@label}" end |
#tick(count = 1) ⇒ Object
19 20 21 22 |
# File 'lib/charming/presentation/components/progressbar.rb', line 19 def tick(count = 1) update(@current + count) self end |
#update(value) ⇒ Object
24 25 26 27 |
# File 'lib/charming/presentation/components/progressbar.rb', line 24 def update(value) @current = value.to_i.clamp(0, @total) self end |