Class: SPNet::SignalOutPort

Inherits:
OutPort
  • Object
show all
Defined in:
lib/spnet/ports/signal_out_port.rb

Overview

Output signal values to a connected SignalInPort object.

Author:

  • James Tunnell

Constant Summary

Constants inherited from OutPort

OutPort::ARG_SPECS

Instance Attribute Summary collapse

Attributes inherited from OutPort

#link, #matching_class, #name

Instance Method Summary collapse

Methods inherited from OutPort

#clear_link, #linked?, #set_link

Constructor Details

#initializeSignalOutPort

A new instance of SignalOutPort.



11
12
13
14
# File 'lib/spnet/ports/signal_out_port.rb', line 11

def initialize
  @queue = []
  super(:matching_class => SignalInPort)
end

Instance Attribute Details

#queueObject (readonly)

Returns the value of attribute queue.



8
9
10
# File 'lib/spnet/ports/signal_out_port.rb', line 8

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)


32
33
34
35
# File 'lib/spnet/ports/signal_out_port.rb', line 32

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, autosend = true) ⇒ Object

Add values to queue or send them directly to linked port (if autosend is true).

Parameters:

  • values (Array)

    The values to add.

  • autosend (true/false) (defaults to: true)

    If true, and this port is linked to another port, skip this port’s queue and enqueue values directly on the linked port’s queue.



22
23
24
25
26
27
28
# File 'lib/spnet/ports/signal_out_port.rb', line 22

def enqueue_values values, autosend = true
  if autosend && linked?
    @link.to.enqueue_values values
  else
    @queue.concat values
  end
end