Class: Patch::Node::Container

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Includes:
Enumerable
Defined in:
lib/patch/node/container.rb

Overview

A container for Patch::Node

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(nodes) ⇒ Container

Returns a new instance of Container.

Parameters:

  • nodes (Array<Object>)


15
16
17
18
# File 'lib/patch/node/container.rb', line 15

def initialize(nodes)
  @threads = []
  @nodes = nodes
end

Instance Attribute Details

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

#enableBoolean

Enable the nodes in this container

Returns:

  • (Boolean)


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

Parameters:

  • :type (Symbol)

    The type of node (eg :midi)

Returns:



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

Parameters:

  • id (Fixnum)

Returns:



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