class AsciiParadise::AsciiCounter

Constants

BROWN
#

BROWN

#
DEFAULT_COUNTDOWN_FROM
#

DEFAULT_COUNTDOWN_FROM

#
N_PADDING
#

N_PADDING

#

Public Class Methods

[](i) click to toggle source
#

Counter[]

#
# File lib/ascii_paradise/animations/counter.rb, line 74
def self.[](i)
 ascii_counter = Counter.new(:dont_run_yet)
 ascii_counter.start_from = i
 ascii_counter.run
end
new( countdown_from = nil, use_this_padding = N_PADDING, run_already = true ) click to toggle source
#

initialize

The second argument is the default padding to use.

#
# File lib/ascii_paradise/animations/counter.rb, line 39
def initialize(
    countdown_from   = nil,
    use_this_padding = N_PADDING,
    run_already      = true
  )
  reset
  set_countdown_from(countdown_from)
  set_padding_to_use(use_this_padding)
  case countdown_from
  when :dont_run_yet
    run_already = false
  end
  run if run_already
end

Public Instance Methods

count_down(i = @countdown_from) click to toggle source
#

count_down

Use this method to count down. We start at 25 for now.

#
# File lib/ascii_paradise/animations/counter.rb, line 85
def count_down(i = @countdown_from)
  i.downto(0).each { |x|
    _ = ( ('%'+@padding_to_use.to_s+'s') % x.to_s)
    print @colour_to_use+R+_
    STDOUT.flush
    begin
      sleep 1
    rescue Interrupt
      puts; exit
    end # Silent rescue.
  }
end
reset() click to toggle source
#

reset

#
# File lib/ascii_paradise/animations/counter.rb, line 57
def reset
  @colour_to_use = BROWN
end
run() click to toggle source
#

run (run tag)

#
# File lib/ascii_paradise/animations/counter.rb, line 110
def run
  count_down
end
set_countdown_from(i = nil) click to toggle source
#

set_countdown_from

#
# File lib/ascii_paradise/animations/counter.rb, line 64
def set_countdown_from(i = nil)
  i = DEFAULT_COUNTDOWN_FROM if i.is_a? Symbol
  i = DEFAULT_COUNTDOWN_FROM if i.nil?
  @countdown_from = i.to_i # Must be Integer.
end
Also aliased as: start_from, start_from=
set_padding_to_use(i) click to toggle source
#

set_padding_to_use

#
# File lib/ascii_paradise/animations/counter.rb, line 101
def set_padding_to_use(i)
  i = i.size if i.is_a? String
  i = i.to_i
  @padding_to_use = i
end
start_from(i = nil)
Alias for: set_countdown_from
start_from=(i = nil)
Alias for: set_countdown_from