Module: NattyUI::Spinner
- Defined in:
- lib/natty-ui/spinner.rb
Overview
Helper class to select spinner types.
Class Attribute Summary collapse
-
.default ⇒ Symbol
writeonly
Define spinner type used by default.
-
.names ⇒ Array<Symbol>
readonly
Defined spinner type names.
Class Method Summary collapse
-
.[](name) ⇒ Enumerator
Spinner definition.
Class Attribute Details
.default=(value) ⇒ Symbol (writeonly)
Define spinner type used by default.
14 15 16 |
# File 'lib/natty-ui/spinner.rb', line 14 def default=(value) @default = self[value.nil? || value == :default ? :pulse : value] end |
.names ⇒ Array<Symbol> (readonly)
Defined spinner type names.
23 |
# File 'lib/natty-ui/spinner.rb', line 23 def names = @all.keys |
Class Method Details
.[](name) ⇒ Enumerator
Returns spinner definition.
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/natty-ui/spinner.rb', line 29 def [](name) return @default if name == :default parts = if name.is_a?(Symbol) @all[name] or raise(ArgumentError, "invalid spinner type - #{name}") else name end parts = (parts.respond_to?(:map) ? parts : parts.to_s.chars).map do |part| "#{@style}#{part}#{Ansi::RESET}" end raise(ArgumentError, "invalid spinner type - #{name}") if parts.empty? parts = parts.zip(parts).flatten(1) while parts.size < 6 Enumerator.new { |y| parts.each { y << _1 } while true } end |