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[         ],
  braille18:  %w[         ],
  braille181: %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.



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

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



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

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

#to_sObject



52
53
54
# File 'lib/infobar/spinner.rb', line 52

def to_s
  @string
end