Class: YPetri::Simulation::Elements
- Inherits:
-
Array
- Object
- Array
- YPetri::Simulation::Elements
- Defined in:
- lib/y_petri/simulation/elements/access.rb,
lib/y_petri/simulation/elements.rb
Overview
Simulation mixin providing access to elements (an element is either a place, or a transition – see also mixins Places::Access
and Transitions::Access
.
Direct Known Subclasses
Defined Under Namespace
Modules: Access
Class Method Summary collapse
-
.load(collection) ⇒ Object
New collection constructor.
Instance Method Summary collapse
-
#load(elements) ⇒ Object
Loads elements to this collection.
-
#sources ⇒ Object
(also: #to_sources)
Returns an array of the element sources (elemens in the original net).
-
#subset(element_ids = nil, &block) ⇒ Object
Creates a subset of this collection (of the same class).
Class Method Details
.load(collection) ⇒ Object
New collection constructor
12 13 14 |
# File 'lib/y_petri/simulation/elements.rb', line 12 def load collection new.tap { |inst| inst.load collection } end |
Instance Method Details
#load(elements) ⇒ Object
Loads elements to this collection.
21 22 23 |
# File 'lib/y_petri/simulation/elements.rb', line 21 def load elements elements.each{ |e| push e } end |
#sources ⇒ Object Also known as: to_sources
Returns an array of the element sources (elemens in the original net).
42 43 44 |
# File 'lib/y_petri/simulation/elements.rb', line 42 def sources map &:source end |
#subset(element_ids = 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 |
# File 'lib/y_petri/simulation/elements.rb', line 27 def subset element_ids=nil, &block if block_given? then msg = "If block is given, arguments are not allowed!" fail ArgumentError, msg unless element_ids.nil? self.class.load select( &block ) else ee = elements( element_ids ) ee.all? { |e| include? e } or fail TypeError, "All subset elements must be in the collection." self.class.load( ee ) end end |