Class: Actor::Filter

Inherits:
Object
  • Object
show all
Defined in:
lib/girl_friday/actor.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeFilter

Returns a new instance of Filter.



431
432
433
434
435
# File 'lib/girl_friday/actor.rb', line 431

def initialize
  @pairs = []
  @timeout = nil
  @timeout_action = nil
end

Instance Attribute Details

#timeoutObject (readonly)

Returns the value of attribute timeout.



428
429
430
# File 'lib/girl_friday/actor.rb', line 428

def timeout
  @timeout
end

#timeout_actionObject (readonly)

Returns the value of attribute timeout_action.



429
430
431
# File 'lib/girl_friday/actor.rb', line 429

def timeout_action
  @timeout_action
end

Instance Method Details

#action_for(value) ⇒ Object



458
459
460
461
# File 'lib/girl_friday/actor.rb', line 458

def action_for(value)
  pair = @pairs.find { |pattern, action| pattern === value }
  pair ? pair.last : nil
end

#after(seconds, &action) ⇒ Object

Raises:

  • (ArgumentError)


447
448
449
450
451
452
453
454
455
456
# File 'lib/girl_friday/actor.rb', line 447

def after(seconds, &action)
  raise ArgumentError, "no block given" unless action

  seconds = seconds.to_f
  if !@timeout or seconds < @timeout
    @timeout = seconds
    @timeout_action = action
  end
  self
end

#timeout?Boolean

Returns:

  • (Boolean)


437
438
439
# File 'lib/girl_friday/actor.rb', line 437

def timeout?
  not @timeout.nil?
end

#when(pattern, &action) ⇒ Object

Raises:

  • (ArgumentError)


441
442
443
444
445
# File 'lib/girl_friday/actor.rb', line 441

def when(pattern, &action)
  raise ArgumentError, "no block given" unless action
  @pairs.push [pattern, action]
  self
end