class TomatoPaste::Timer

Attributes

current[R]
duration[R]
interval_duration[W]
state[R]

Public Class Methods

new(duration) click to toggle source
# File lib/tomato_paste/timer.rb, line 8
def initialize(duration)
  @duration = duration
  @current = 0
  @state = :idle
  @interval_duration = 1
end

Public Instance Methods

done?() click to toggle source
# File lib/tomato_paste/timer.rb, line 20
def done?
  @state == :done
end
start() click to toggle source
# File lib/tomato_paste/timer.rb, line 15
def start
  @state = :running
  time_becomes_a_loop
end

Private Instance Methods

time_becomes_a_loop() click to toggle source

Orbital www.youtube.com/watch?v=7Ab_VDg4M1s

# File lib/tomato_paste/timer.rb, line 26
def time_becomes_a_loop
  progress_bar = ProgressBar.create(:format => 'Elapsed %a [%B] %p%%',
                                    :total => @duration,
                                    :smoothing => 0.6)

  while @current < @duration
    Kernel.sleep @interval_duration
    @current += 1
    progress_bar.increment
  end

  @state = :done
end