Class: PetriNet::ReachabilityGraph::Node

Inherits:
Base
  • Object
show all
Defined in:
lib/petri_net/node.rb

Instance Attribute Summary collapse

Attributes inherited from Base

#logger

Instance Method Summary collapse

Methods inherited from Base

#next_object_id, #reset

Constructor Details

#initialize(options = {}) {|_self| ... } ⇒ Node

Returns a new instance of Node.

Yields:

  • (_self)

Yield Parameters:



11
12
13
14
15
16
17
18
19
20
21
# File 'lib/petri_net/node.rb', line 11

def initialize(options = {}, &block)
    @id = next_object_id
    @name = (options[:name] or "Node#{@id}")
    @description = (options[:description] or "Node #{@id}")
    @inputs = Array.new
    @outputs = Array.new
    @label = (options[:label] or @name)
    @markings = options[:markings] 

    yield self unless block.nil?
end

Instance Attribute Details

#graphObject

The graph this node belongs to



9
10
11
# File 'lib/petri_net/node.rb', line 9

def graph
  @graph
end

#idObject (readonly)

unique ID



5
6
7
# File 'lib/petri_net/node.rb', line 5

def id
  @id
end

#markingsObject (readonly)

Makking this node represents



7
8
9
# File 'lib/petri_net/node.rb', line 7

def markings
  @markings
end

#nameObject (readonly)

human readable name



3
4
5
# File 'lib/petri_net/node.rb', line 3

def name
  @name
end

Instance Method Details

#==(object) ⇒ Object



35
36
37
38
# File 'lib/petri_net/node.rb', line 35

def ==(object)
    return false unless object.class.to_s == "PetriNet::ReachabilityGraph::Node"
    @markings == object.markings
end

#gv_idObject



27
28
29
# File 'lib/petri_net/node.rb', line 27

def gv_id
    "N#{@id}"
end

#to_gvObject



31
32
33
# File 'lib/petri_net/node.rb', line 31

def to_gv
    "\t#{self.gv_id} [ label = \"#{@markings}\" ];\n"
end

#to_sObject



40
41
42
# File 'lib/petri_net/node.rb', line 40

def to_s
    "#{@id}: #{@name} (#{@markings})"
end

#validateObject



23
24
25
# File 'lib/petri_net/node.rb', line 23

def validate
    true
end