class RFlow::Component::PortCollection

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

Attributes

by_name[R]

All the ports in the collection, indexed by name. @return [Hash<String, Port>]

by_type[R]

All the ports in the collection, indexed by type ({InputPort}, {OutputPort}). @return [Hash<String, Array<Port>>]

ports[R]

All the ports in the collection. @return [Array<Port>]

Public Class Methods

new() click to toggle source
# File lib/rflow/component/port.rb, line 27
def initialize
  @ports = []
  @by_name = {}
  @by_type = Hash.new {|hash, key| hash[key.to_s] = []}
end

Public Instance Methods

<<(port) click to toggle source

Add a port to the collection. @param port [Port] port to add @return [PortCollection] self

# 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
each() { |port| ... } click to toggle source

Enumerate through each port, +yield+ing each. TODO: simplify with enumerators and procs @return [Array<Port>]

# File lib/rflow/component/port.rb, line 46
def each
  ports.each {|port| yield port }
end