class AsciiParadise::ProgressBar

Constants

INTERVAL
#

INTERVAL

How long we will wait. The larger, the slower the progress-bar will appear.

#
LENGTH
#

The length of the AsciiBar comes next. The higher, the longer the bar.

#
START
#

START

#

Public Class Methods

new( run_already = true ) click to toggle source
#

initialize

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

Public Instance Methods

reset() click to toggle source
#

reset

#
# File lib/ascii_paradise/animations/progress_bar.rb, line 48
def reset
  @length = LENGTH
end
run() click to toggle source
#

run

#
# File lib/ascii_paradise/animations/progress_bar.rb, line 77
def run
  run_the_progress_bar
end
run_the_progress_bar() click to toggle source
#

run_the_progress_bar

#
# File lib/ascii_paradise/animations/progress_bar.rb, line 55
def run_the_progress_bar
  @length.times {|i|
    output_string = START.dup # Need .dup here because otherwise the START-string will be appended.
    @length.times {|x|
      # =================================================================== #
      # Next we build up our output string. This string will fluctate
      # at every interval.
      # =================================================================== #
      output_string << (
        x == i && ( i % 2 == 0 && 'C'||'c')|| (x < i && '-' || ( x % 2 == 0 && ' '|| 'o' ))
      )
    }
    print output_string+']'
    STDOUT.flush
    sleep INTERVAL
  }
  e
end