Class: Patch::Node::Container
- Inherits:
-
Object
- Object
- Patch::Node::Container
- Extended by:
- Forwardable
- Includes:
- Enumerable
- Defined in:
- lib/patch/node/container.rb
Overview
A container for Patch::Node
Instance Attribute Summary collapse
-
#nodes ⇒ Object
readonly
Returns the value of attribute nodes.
Instance Method Summary collapse
- #each(&block) ⇒ Object
-
#enable ⇒ Boolean
Enable the nodes in this container.
-
#find_all_by_type(type) ⇒ Array<IO::MIDI, IO::OSC, IO::Websocket>
Get the nodes of the given type.
-
#find_by_id(id) ⇒ IO::MIDI, ...
Find the node with the given id.
-
#initialize(nodes) ⇒ Container
constructor
A new instance of Container.
- #|(other) ⇒ Object
Constructor Details
#initialize(nodes) ⇒ Container
Returns a new instance of Container.
15 16 17 18 |
# File 'lib/patch/node/container.rb', line 15 def initialize(nodes) @threads = [] @nodes = nodes end |
Instance Attribute Details
#nodes ⇒ Object (readonly)
Returns the value of attribute nodes.
11 12 13 |
# File 'lib/patch/node/container.rb', line 11 def nodes @nodes end |
Instance Method Details
#each(&block) ⇒ Object
24 25 26 |
# File 'lib/patch/node/container.rb', line 24 def each(&block) @nodes.each(&block) end |
#enable ⇒ Boolean
Enable the nodes in this container
30 31 32 33 |
# File 'lib/patch/node/container.rb', line 30 def enable result = @nodes.map { |node| enable_node(node) } result.any? end |
#find_all_by_type(type) ⇒ Array<IO::MIDI, IO::OSC, IO::Websocket>
Get the nodes of the given type
38 39 40 41 42 43 44 |
# File 'lib/patch/node/container.rb', line 38 def find_all_by_type(type) if (mod = IO::Module.find_by_key(type)).nil? [] else @nodes.select { |node| node.class.name.match(/\A#{mod.name}/) } end end |
#find_by_id(id) ⇒ IO::MIDI, ...
Find the node with the given id
49 50 51 |
# File 'lib/patch/node/container.rb', line 49 def find_by_id(id) @nodes.find { |node| node.id == id } end |
#|(other) ⇒ Object
20 21 22 |
# File 'lib/patch/node/container.rb', line 20 def |(other) @nodes | other.nodes end |