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 ⇒ Object
readonly
Returns the value of attribute by_name.
-
#by_type ⇒ Object
readonly
Returns the value of attribute by_type.
-
#ports ⇒ Object
readonly
Returns the value of attribute ports.
Instance Method Summary collapse
- #<<(port) ⇒ Object
-
#each ⇒ Object
Enumerate through each port TODO: simplify with enumerators and procs.
-
#initialize ⇒ PortCollection
constructor
A new instance of PortCollection.
Constructor Details
#initialize ⇒ PortCollection
Returns a new instance of PortCollection.
17 18 19 20 21 |
# File 'lib/rflow/component/port.rb', line 17 def initialize @ports = [] @by_name = {} @by_type = Hash.new {|hash, key| hash[key.to_s] = []} end |
Instance Attribute Details
#by_name ⇒ Object (readonly)
Returns the value of attribute by_name.
15 16 17 |
# File 'lib/rflow/component/port.rb', line 15 def by_name @by_name end |
#by_type ⇒ Object (readonly)
Returns the value of attribute by_type.
15 16 17 |
# File 'lib/rflow/component/port.rb', line 15 def by_type @by_type end |
#ports ⇒ Object (readonly)
Returns the value of attribute ports.
15 16 17 |
# File 'lib/rflow/component/port.rb', line 15 def ports @ports end |
Instance Method Details
#<<(port) ⇒ Object
23 24 25 26 27 28 |
# File 'lib/rflow/component/port.rb', line 23 def <<(port) by_name[port.name.to_s] = port by_type[port.class.to_s] << port ports << port self end |
#each ⇒ Object
Enumerate through each port TODO: simplify with enumerators and procs
32 33 34 |
# File 'lib/rflow/component/port.rb', line 32 def each ports.each {|port| yield port } end |