Class: Petri::Net
- Inherits:
-
Object
- Object
- Petri::Net
- Defined in:
- lib/petri/net.rb
Instance Method Summary collapse
- #add_place(place, options = {}) ⇒ Object
- #compile ⇒ Object
- #end_place(label, options = {}) ⇒ Object
-
#initialize(options = {}, &block) ⇒ Net
constructor
A new instance of Net.
- #start_place(label, options = {}) ⇒ Object
- #transition(label, options = {}, &block) ⇒ Object
Constructor Details
#initialize(options = {}, &block) ⇒ Net
Returns a new instance of Net.
2 3 4 5 6 7 8 |
# File 'lib/petri/net.rb', line 2 def initialize(={}, &block) @places = [] @transitions = [] @start = nil @end = nil block.call(self) end |
Instance Method Details
#add_place(place, options = {}) ⇒ Object
10 11 12 13 14 15 16 17 |
# File 'lib/petri/net.rb', line 10 def add_place(place, ={}) entity = place if place.is_a? Petri::Place entity = Petri::Place.new(place, ) if place.is_a? Symbol raise TypeError unless entity.is_a? Petri::Place @places << entity unless @places.include?(entity) entity end |
#compile ⇒ Object
35 36 37 38 39 40 41 42 |
# File 'lib/petri/net.rb', line 35 def compile { places: @places.map { |place| place.compile }, transitions: @transitions.map { |transition| transition.compile }, start_place: @start, end_place: @end, } end |
#end_place(label, options = {}) ⇒ Object
24 25 26 27 |
# File 'lib/petri/net.rb', line 24 def end_place(label, ={}) place = add_place(label, ) @end = place.label end |
#start_place(label, options = {}) ⇒ Object
19 20 21 22 |
# File 'lib/petri/net.rb', line 19 def start_place(label, ={}) place = add_place(label, ) @start = place.label end |
#transition(label, options = {}, &block) ⇒ Object
29 30 31 32 33 |
# File 'lib/petri/net.rb', line 29 def transition(label, ={}, &block) raise TypeError unless label.is_a? Symbol raise ArgumentError if @transitions.include? label @transitions << Petri::Transition.new(self, label, , &block) end |