Class: Shattered::Timer::TimedEvent

Inherits:
Object
  • Object
show all
Defined in:
lib/shattered_model/timed_event.rb

Direct Known Subclasses

ContinuousTimedEvent

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(context, seconds, options = {}, &block) ⇒ TimedEvent

Returns a new instance of TimedEvent.



46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/shattered_model/timed_event.rb', line 46

def initialize(context, seconds, options={}, &block)
  @context=context
  @event = block
  @options = options
  if(seconds != :frame)
    @time_remaining = seconds
    @initial_time = @time_remaining
  else
    @time_remaining = 0
    @initial_time = 0
  end
end

Instance Attribute Details

#time_remainingObject

Returns the value of attribute time_remaining.



45
46
47
# File 'lib/shattered_model/timed_event.rb', line 45

def time_remaining
  @time_remaining
end

Instance Method Details

#processed?Boolean

Returns:

  • (Boolean)


66
67
68
# File 'lib/shattered_model/timed_event.rb', line 66

def processed?
  return @processed == true
end

#resetObject



69
70
71
# File 'lib/shattered_model/timed_event.rb', line 69

def reset
  @time_remaining = @initial_time
end

#stopObject

Stop the timer



73
74
75
# File 'lib/shattered_model/timed_event.rb', line 73

def stop
  @stopped = true
end

#stopped?Boolean

Returns:

  • (Boolean)


76
77
78
# File 'lib/shattered_model/timed_event.rb', line 76

def stopped?
  !@stopped.nil?
end

#update(time_elapsed) ⇒ Object



58
59
60
61
62
63
64
65
# File 'lib/shattered_model/timed_event.rb', line 58

def update(time_elapsed)
  return if processed? || stopped?
  @time_remaining -= time_elapsed
  if time_up?
    process_event
    @processed=true
  end
end