Module: NattyUI::Spinner

Defined in:
lib/natty-ui/spinner.rb

Overview

Helper class to select spinner types.

See Also:

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.default=(value) ⇒ Symbol (writeonly)

Define spinner type used by default.

Parameters:

  • value (Symbol)

    type name

Returns:

  • (Symbol)

    type name



14
15
16
# File 'lib/natty-ui/spinner.rb', line 14

def default=(value)
  @default = self[value.nil? || value == :default ? :pulse : value]
end

.namesArray<Symbol> (readonly)

Defined spinner type names.

Returns:

  • (Array<Symbol>)

    supported attribute names

See Also:



23
# File 'lib/natty-ui/spinner.rb', line 23

def names = @all.keys

Class Method Details

.[](name) ⇒ Enumerator

Returns spinner definition.

Parameters:

  • name (Symbol, #to_a, #to_s)

    defined type name (see names) or spinner elements

Returns:

  • (Enumerator)

    spinner definition

Raises:

  • (ArgumentError)


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