Class: SPNet::SignalInPort

Inherits:
InPort
  • Object
show all
Includes:
Hashmake::HashMakeable
Defined in:
lib/spnet/ports/signal_in_port.rb

Overview

Recieves signal input for processing in a Block object.

Author:

  • James Tunnell

Constant Summary collapse

ARG_SPECS =

Define arg specs to use in processing hashed arguments during #initialize.

{
  :limiter => arg_spec(:reqd => false, :type => Limiter, :default => ->(){ NoLimiter.new }, :validator => ->(a){ !a.is_a?(EnumLimiter) }),
}

Instance Attribute Summary collapse

Attributes inherited from InPort

#link, #matching_class

Instance Method Summary collapse

Methods inherited from InPort

#clear_link, #linked?, #set_link

Constructor Details

#initialize(hashed_args = {}) ⇒ SignalInPort

A new instance of SignalInPort.

Parameters:

  • hashed_args (Hash) (defaults to: {})

    Hashed arguments for initialization. See Network::ARG_SPECS for details.



20
21
22
23
24
25
26
27
# File 'lib/spnet/ports/signal_in_port.rb', line 20

def initialize hashed_args = {}
  hash_make hashed_args, SignalInPort::ARG_SPECS
  
  @queue = []
  @skip_limiting = @limiter.is_a?(NoLimiter)

  super(:matching_class => SignalOutPort)
end

Instance Attribute Details

#limiterObject (readonly)

Returns the value of attribute limiter.



15
16
17
# File 'lib/spnet/ports/signal_in_port.rb', line 15

def limiter
  @limiter
end

#queueObject (readonly)

Returns the value of attribute queue.



15
16
17
# File 'lib/spnet/ports/signal_in_port.rb', line 15

def queue
  @queue
end

Instance Method Details

#dequeue_values(count = @queue.count) ⇒ Object

Remove values to queue.

Parameters:

  • count (Fixnum) (defaults to: @queue.count)

    Number of values to remove.

Raises:

  • (ArgumentError)


42
43
44
45
# File 'lib/spnet/ports/signal_in_port.rb', line 42

def dequeue_values count = @queue.count
  raise ArgumentError, "count is greater than @queue.count" if count > @queue.count
  @queue.slice!(0...count)
end

#enqueue_values(values) ⇒ Object

Add values to queue.



30
31
32
33
34
35
36
37
38
# File 'lib/spnet/ports/signal_in_port.rb', line 30

def enqueue_values values
  unless @skip_limiting
    for i in 0...values.count
      values[i] = @limiter.apply_limit values[i]
    end
  end
  
  @queue.concat values
end