class YPetri::Simulation::Nodes

An array of simulation-owned places and/or transitions.

Simulation mixin providing access to nodes (places / transitions). Also see mixins Places::Access and Transitions::Access.

Public Class Methods

load(collection) click to toggle source

New collection constructor

# File lib/y_petri/simulation/nodes.rb, line 12
def load collection
  new.tap { |inst| inst.load collection }
end

Public Instance Methods

load(nodes) click to toggle source

Loads nodes to this collection.

# File lib/y_petri/simulation/nodes.rb, line 21
def load nodes
  nodes.each{ |node| push node }
end
sources() click to toggle source

Returns an array of the node sources (nodes in the underlying net).

# File lib/y_petri/simulation/nodes.rb, line 43
def sources
  map &:source
end
Also aliased as: to_sources
subset(nodes=nil, &block) click to toggle source

Creates a subset of this collection (of the same class).

# File lib/y_petri/simulation/nodes.rb, line 27
def subset nodes=nil, &block # TODO: Rename to subarray
  if block_given? then
    fail ArgumentError, "If block given, arguments not allowed!" unless
      nodes.nil?
    self.class.load select( &block )
  else
    fail ArgumentError, "A collection or a block expected!" if nodes.nil?
    nn = Nodes( nodes )
    nn.all? { |node| include? node } or
      fail TypeError, "All subset elements must be in the collection."
    self.class.load( nn )
  end
end
to_sources()
Alias for: sources