Class: RFlow::Component::PortCollection
- Inherits:
-
Object
- Object
- RFlow::Component::PortCollection
- 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
-
#by_name ⇒ Hash<String, Port>
readonly
All the ports in the collection, indexed by name.
-
#by_type ⇒ Hash<String, Array<Port>>
readonly
All the ports in the collection, indexed by type (InputPort, OutputPort).
-
#ports ⇒ Array<Port>
readonly
All the ports in the collection.
Instance Method Summary collapse
-
#<<(port) ⇒ PortCollection
Add a port to the collection.
-
#each ⇒ Array<Port>
Enumerate through each port, yielding each.
-
#initialize ⇒ PortCollection
constructor
A new instance of PortCollection.
Constructor Details
#initialize ⇒ 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_name ⇒ Hash<String, Port> (readonly)
All the ports in the collection, indexed by name.
22 23 24 |
# File 'lib/rflow/component/port.rb', line 22 def by_name @by_name end |
#by_type ⇒ Hash<String, Array<Port>> (readonly)
All the ports in the collection, indexed by type (InputPort, OutputPort).
25 26 27 |
# File 'lib/rflow/component/port.rb', line 25 def by_type @by_type end |
#ports ⇒ Array<Port> (readonly)
All the ports in the collection.
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.
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 |
#each ⇒ Array<Port>
Enumerate through each port, yielding each. TODO: simplify with enumerators and procs
46 47 48 |
# File 'lib/rflow/component/port.rb', line 46 def each ports.each {|port| yield port } end |