Class: Charming::Components::Spinner
- Inherits:
-
Charming::Component
- Object
- View
- Charming::Component
- Charming::Components::Spinner
- Defined in:
- lib/charming/components/spinner.rb
Constant Summary collapse
- DEFAULT_FRAMES =
["-", "\\", "|", "/"].freeze
Instance Attribute Summary collapse
-
#frames ⇒ Object
readonly
Returns the value of attribute frames.
-
#index ⇒ Object
readonly
Returns the value of attribute index.
-
#label ⇒ Object
readonly
Returns the value of attribute label.
Instance Method Summary collapse
-
#initialize(frames: DEFAULT_FRAMES, index: 0, label: nil) ⇒ Spinner
constructor
A new instance of Spinner.
- #render ⇒ Object
- #tick ⇒ Object
Methods inherited from View
Constructor Details
#initialize(frames: DEFAULT_FRAMES, index: 0, label: nil) ⇒ Spinner
Returns a new instance of Spinner.
10 11 12 13 14 15 16 17 |
# File 'lib/charming/components/spinner.rb', line 10 def initialize(frames: DEFAULT_FRAMES, index: 0, label: nil) super() raise ArgumentError, "frames cannot be empty" if frames.empty? @frames = frames @index = index @label = label end |
Instance Attribute Details
#frames ⇒ Object (readonly)
Returns the value of attribute frames.
8 9 10 |
# File 'lib/charming/components/spinner.rb', line 8 def frames @frames end |
#index ⇒ Object (readonly)
Returns the value of attribute index.
8 9 10 |
# File 'lib/charming/components/spinner.rb', line 8 def index @index end |
#label ⇒ Object (readonly)
Returns the value of attribute label.
8 9 10 |
# File 'lib/charming/components/spinner.rb', line 8 def label @label end |
Instance Method Details
#render ⇒ Object
24 25 26 27 28 |
# File 'lib/charming/components/spinner.rb', line 24 def render return frame unless label "#{frame} #{label}" end |
#tick ⇒ Object
19 20 21 22 |
# File 'lib/charming/components/spinner.rb', line 19 def tick @index = (index + 1) % frames.length self end |