Class: Packet::Event

Inherits:
Object
  • Object
show all
Defined in:
lib/packet/packet_event.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(elapsed_time, &block) ⇒ Event

Returns a new instance of Event.



4
5
6
7
8
9
# File 'lib/packet/packet_event.rb', line 4

def initialize(elapsed_time,&block)
  @cancel_flag = false
  @timer_signature = Guid.hexdigest
  @block = block
  @scheduled_time = Time.now + elapsed_time
end

Instance Attribute Details

#blockObject

Returns the value of attribute block.



3
4
5
# File 'lib/packet/packet_event.rb', line 3

def block
  @block
end

#cancel_flagObject

Returns the value of attribute cancel_flag.



3
4
5
# File 'lib/packet/packet_event.rb', line 3

def cancel_flag
  @cancel_flag
end

#scheduled_timeObject

Returns the value of attribute scheduled_time.



3
4
5
# File 'lib/packet/packet_event.rb', line 3

def scheduled_time
  @scheduled_time
end

#timer_signatureObject

Returns the value of attribute timer_signature.



3
4
5
# File 'lib/packet/packet_event.rb', line 3

def timer_signature
  @timer_signature
end

Instance Method Details

#cancelObject



16
17
18
# File 'lib/packet/packet_event.rb', line 16

def cancel
  @cancel_flag = true
end

#runObject



20
21
22
# File 'lib/packet/packet_event.rb', line 20

def run
  @block.call
end

#run_now?Boolean

Returns:

  • (Boolean)


11
12
13
14
# File 'lib/packet/packet_event.rb', line 11

def run_now?
  return true if @scheduled_time <= Time.now
  return false
end