Class: Infobar::Spinner

Inherits:
Object show all
Defined in:
lib/infobar/spinner.rb

Constant Summary collapse

PREDEFINED =
{
  pipe:      %w[ | / – \\ ],
  arrow:     %w[ ↑ ↗ → ↘ ↓ ↙ ← ↖ ],
  bar1:      %w[ ▁ ▂ ▃ ▄ ▅ ▆ ▇ █ ▇ ▆ ▅ ▄ ▃ ▂ ],
  bar2:      %w[ █ ▉ ▊ ▋ ▌ ▍ ▎ ▏ ▎ ▍ ▌ ▋ ▊ ▉ ],
  braille7:  %w[ ⣾ ⣽ ⣻ ⢿ ⡿ ⣟ ⣯ ⣷ ],
  braille1:  %w[ ⠁ ⠂ ⠄ ⡀ ⢀ ⠠ ⠐ ⠈ ],
  square1:   %w[ ▖ ▘ ▝ ▗ ],
  square2:   %w[ ◰ ◳ ◲ ◱ ],
  tetris:    %w[ ▌ ▀ ▐▄ ],
  eyes:      %w[ ◡◡ ⊙⊙ ◠◠ ],
  corners:   %w[ ┤ ┘ ┴ └ ├ ┌ ┬ ┐ ],
  triangle:  %w[ ◢ ◣ ◤ ◥ ],
  circle1:   %w[ ◴ ◷ ◶ ◵ ],
  circle2:   %w[ ◐ ◓ ◑ ◒ ],
  circle3:   %w[ ◜ ◝ ◞ ◟ ],
  cross:     %w[ + × ],
  cylon:     [ '●  ', ' ● ', '  ●', ' ● ' ],
  pacman:    [ 'ᗧ∙∙∙∙●', ' O∙∙∙●', '  ᗧ∙∙●','   O∙●', '    ᗧ●', 'ᗣ    O', ' ᗣ   ᗤ', ' ᗣ  O ', ' ᗣ ᗤ  ', ' ᗣO   ', ' ᗤ    ', 'O ∞   ', 'ᗧ   ∞ ', 'O     ' ],
  asteroids: [ 'ᐊ  ◍', 'ᐃ  ◍', 'ᐓ  ◍', 'ᐅ· ◍', 'ᐅ ·◍', 'ᐅ  ○', 'ᐅ  ◌', 'ᐁ   ' ],
  clock:     %w[ 🕐 🕜 🕑 🕝 🕒 🕞 🕓 🕟 🕔 🕠 🕕 🕡 🕖 🕢 🕗 🕣 🕘 🕤 🕙 🕥 🕚 🕦 🕛 🕧 ],
  hourglass: %w[ ⏳ ⌛ ],
}

Instance Method Summary collapse

Constructor Details

#initialize(frames = nil) ⇒ Spinner

Returns a new instance of Spinner.



26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/infobar/spinner.rb', line 26

def initialize(frames = nil)
  @frames =
    case frames
    when Array
      frames
    when Symbol
      PREDEFINED.fetch(frames) do
        |k| raise KeyError, "frames #{k} not predefined"
      end
    when nil
      PREDEFINED[:pipe]
    end
end

Instance Method Details

#spin(count) ⇒ Object



40
41
42
43
44
45
46
47
48
# File 'lib/infobar/spinner.rb', line 40

def spin(count)
  @string =
    if count == :random
      @frames[rand(@frames.size)]
    else
      @frames[count % @frames.size]
    end
  self
end

#to_sObject



50
51
52
# File 'lib/infobar/spinner.rb', line 50

def to_s
  @string
end