class Sphyg::Throbber

Generates and displays a throbber with a message

Public Class Methods

new(message, frames, enumerator, rate) click to toggle source
# File lib/sphyg/throbber.rb, line 7
def initialize(message, frames, enumerator, rate)
  @message = message
  @frames = frames
  @enumerator = Object.const_get(enumerator).new(@frames)
  @rate = rate
end

Public Instance Methods

run() click to toggle source
# File lib/sphyg/throbber.rb, line 14
def run
  loop do
    print_throbber_iteration
    sleep @rate
  end
end

Private Instance Methods

padding() click to toggle source

For unitary-frame loops, if a frame is longer than its counterparts, then it will not be completely replaced by the following frame. This padding ensures that each line is long enough to overwrite the previous frame.

# File lib/sphyg/throbber.rb, line 27
def padding
  @_padding ||= "\s" * @frames.max_by(&:length).length
end
print_throbber_iteration() click to toggle source