Class: YPetri::Simulation::Nodes

Inherits:
Array
  • Object
show all
Defined in:
lib/y_petri/simulation/nodes.rb,
lib/y_petri/simulation/nodes/access.rb

Overview

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

Direct Known Subclasses

Places, Transitions

Defined Under Namespace

Modules: Access

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.load(collection) ⇒ Object

New collection constructor



12
13
14
# File 'lib/y_petri/simulation/nodes.rb', line 12

def load collection
  new.tap { |inst| inst.load collection }
end

Instance Method Details

#load(nodes) ⇒ Object

Loads nodes to this collection.



21
22
23
# File 'lib/y_petri/simulation/nodes.rb', line 21

def load nodes
  nodes.each{ |node| push node }
end

#sourcesObject Also known as: to_sources

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



43
44
45
# File 'lib/y_petri/simulation/nodes.rb', line 43

def sources
  map &:source
end

#subset(nodes = nil, &block) ⇒ Object

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



27
28
29
30
31
32
33
34
35
36
37
38
39
# 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