Sha256: df71aec79b94bd1cb5039a799dcc479b74e994518bdb9b6e82ecde5a24723829

Contents?: true

Size: 1.12 KB

Versions: 32

Compression:

Stored size: 1.12 KB

Contents

# encoding: utf-8

# Basic elements of a simulation, a mixin intended for YPetri::Simulation.
# 
class YPetri::Simulation
  class Elements < Array
    ★ Dependency

    class << self
      # New collection constructor
      #
      def load collection
        new.tap { |inst| inst.load collection }
      end
    end

    delegate :simulation, to: "self.class"

    # Loads elements to this collection.
    #
    def load elements
      elements.each{ |e| push e }
    end

    # Creates a subset of this collection (of the same class).
    # 
    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

    # Returns an array of the element sources (elemens in the original net).
    # 
    def sources
      map &:source
    end
    alias to_sources sources
  end
end

Version data entries

32 entries across 32 versions & 1 rubygems

Version Path
y_petri-2.2.4 lib/y_petri/simulation/elements.rb
y_petri-2.2.3 lib/y_petri/simulation/elements.rb
y_petri-2.2.2 lib/y_petri/simulation/elements.rb
y_petri-2.2.1 lib/y_petri/simulation/elements.rb
y_petri-2.2.0 lib/y_petri/simulation/elements.rb
y_petri-2.1.51 lib/y_petri/simulation/elements.rb
y_petri-2.1.50 lib/y_petri/simulation/elements.rb
y_petri-2.1.49 lib/y_petri/simulation/elements.rb
y_petri-2.1.48 lib/y_petri/simulation/elements.rb
y_petri-2.1.47 lib/y_petri/simulation/elements.rb
y_petri-2.1.46 lib/y_petri/simulation/elements.rb
y_petri-2.1.45 lib/y_petri/simulation/elements.rb
y_petri-2.1.44 lib/y_petri/simulation/elements.rb
y_petri-2.1.42 lib/y_petri/simulation/elements.rb
y_petri-2.1.40 lib/y_petri/simulation/elements.rb
y_petri-2.1.39 lib/y_petri/simulation/elements.rb
y_petri-2.1.37 lib/y_petri/simulation/elements.rb
y_petri-2.1.36 lib/y_petri/simulation/elements.rb
y_petri-2.1.35 lib/y_petri/simulation/elements.rb
y_petri-2.1.34 lib/y_petri/simulation/elements.rb