class AsciiParadise::RotatingSlash

Constants

ARRAY
#

ARRAY

This constant is an Array that keeps the different tokens which will be displayed on the commandline.

Note that the last character in that array, the '/', will be the token that we will keep displayed.

There are six entries in this Array.

#
BACKSPACE
#

BACKSPACE

#
DEFAULT_DELAY
#

DEFAULT_DELAY

#

Public Class Methods

new( run_already = true ) click to toggle source
#

initialize

#
# File lib/ascii_paradise/animations/rotating_slash.rb, line 39
def initialize(
    run_already = true
  )
  register_sigint
  reset
  run if run_already
end

Public Instance Methods

can_we_finish?() click to toggle source
#

can_we_finish?

#
# File lib/ascii_paradise/animations/rotating_slash.rb, line 57
def can_we_finish?
  rand(300) == 0
end
delay?() click to toggle source
#

delay?

#
# File lib/ascii_paradise/animations/rotating_slash.rb, line 71
def delay?
  @delay
end
reset() click to toggle source
#

reset

#
# File lib/ascii_paradise/animations/rotating_slash.rb, line 50
def reset
  @delay = DEFAULT_DELAY # We use this default.
end
run() click to toggle source
#

run

#
# File lib/ascii_paradise/animations/rotating_slash.rb, line 78
def run
  # ======================================================================= #
  # The tokens are those that will appear to "dance".
  # ======================================================================= #
  $stdout.sync = true # must be true else we won't see a thing.
  loop {
    print ARRAY.unshift(ARRAY.pop).last
    sleep delay?
    print BACKSPACE
    if can_we_finish? # Randomly finish here, via a message.
      show_finish_message
      break
    end
  }
end
show_finish_message() click to toggle source
#

finish

#
# File lib/ascii_paradise/animations/rotating_slash.rb, line 64
def show_finish_message # finish and end here.
  puts 'Finished!'
end