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.



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_nameObject (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_typeObject (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

#portsObject (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

#eachObject

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