Class: RFlow::Component::PortCollection

Inherits:
Object
  • Object
show all
Defined in:
lib/rflow/component/port.rb

Overview

Collection class to make it easier to index by both names and types.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializePortCollection

Returns a new instance of PortCollection.



27
28
29
30
31
# File 'lib/rflow/component/port.rb', line 27

def initialize
  @ports = []
  @by_name = {}
  @by_type = Hash.new {|hash, key| hash[key.to_s] = []}
end

Instance Attribute Details

#by_nameHash<String, Port> (readonly)

All the ports in the collection, indexed by name.

Returns:

  • (Hash<String, Port>)


22
23
24
# File 'lib/rflow/component/port.rb', line 22

def by_name
  @by_name
end

#by_typeHash<String, Array<Port>> (readonly)

All the ports in the collection, indexed by type (InputPort, OutputPort).

Returns:

  • (Hash<String, Array<Port>>)


25
26
27
# File 'lib/rflow/component/port.rb', line 25

def by_type
  @by_type
end

#portsArray<Port> (readonly)

All the ports in the collection.

Returns:



19
20
21
# File 'lib/rflow/component/port.rb', line 19

def ports
  @ports
end

Instance Method Details

#<<(port) ⇒ PortCollection

Add a port to the collection.

Parameters:

  • port (Port)

    port to add

Returns:



36
37
38
39
40
41
# File 'lib/rflow/component/port.rb', line 36

def <<(port)
  by_name[port.name.to_s] = port
  by_type[port.class.to_s] << port
  ports << port
  self
end

#eachArray<Port>

Enumerate through each port, yielding each. TODO: simplify with enumerators and procs

Returns:



46
47
48
# File 'lib/rflow/component/port.rb', line 46

def each
  ports.each {|port| yield port }
end