Sha256: 58dc99c119dfa4dab1c97438fc19e53b2a3182a425c3db9df7439117e7519b26

Contents?: true

Size: 1.41 KB

Versions: 35

Compression:

Stored size: 1.41 KB

Contents

#encoding: utf-8

# Simulation mixin providing access to elements (an element is either a
# place, or a transition -- see also mixins +Places::Access+ and
# +Transitions::Access+.
# 
class YPetri::Simulation::Elements
  module Access
    # Does an element belong to the simulation?
    # 
    def includes?( id )
      includes_place?( id ) || includes_transition?( id )
    end
    alias include? includes?

    # Element of the simulation (belonging to the net).
    # 
    def e( id )
      element( id ).source
    end

    # Elements of the simulation (belonging to the net).
    # 
    def ee( ids=nil )
      elements( ids ).map &:source
    end

    # Names of the simulation's elements. Arguments, if any, are treated
    # analogically to the +#elements+ method.
    # 
    def en ids=nil
      elements( ids ).names
    end

    protected

    # Element instance identification.
    # 
    def element( id )
      if include_place? id
        return place( id )
      end
      if include_transition? id
        return transition( id )
      end
      fail TypeError, "No element #{id} in the simulation!"
    end

    # Without arguments, returns all the elements (places + transitions). If
    # arguments are given, they are converted into elements.
    # 
    def elements ids=nil
      return places + transitions if ids.nil?
      ids.map { |id| element id }
    end
  end # module Access
end # class YPetri::Simulation::Elements

Version data entries

35 entries across 35 versions & 1 rubygems

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