Class: Graphm::Render::PathRenderer

Inherits:
Object
  • Object
show all
Defined in:
lib/graphm/render/path.rb

Instance Method Summary collapse

Constructor Details

#initializePathRenderer

Returns a new instance of PathRenderer.



10
11
12
13
# File 'lib/graphm/render/path.rb', line 10

def initialize
	@incomplete = []
	@complete = []
end

Instance Method Details

#render_edge(edge) ⇒ Object



57
58
59
60
61
62
63
64
# File 'lib/graphm/render/path.rb', line 57

def render_edge edge
	res = if edge.has_prop? :label then
			  "[%s]-->" % edge.prop[:label]
		  else
			  "-->" 
		  end
	return res
end

#render_graph(graph) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/graphm/render/path.rb', line 15

def render_graph graph
	# create a path for each init node
	ini = graph.nodes.map{ |name,node| node }.reject{ |node| not node.has_prop? :initial }

	ini.each do |node|
		@incomplete << [ node ]
	end

	# while there is an incomplete path
	while not @incomplete.empty? do
		cur_path = @incomplete.shift

		node = cur_path.last
		node.edges.each do |edge|
			next if cur_path.include? edge

			node_path = cur_path + [ edge, edge.dst ]
			if edge.dst.has_prop? :final then
				@complete << node_path
			else
				@incomplete << node_path
			end
		end
	end

	res = []
	res = @complete.map do |path|
		rpath = path.map do |elem|
			case elem
			when Node then render_node elem
			when Edge then render_edge elem
			end
		end
		rpath
	end
	return res
end

#render_node(node) ⇒ Object



53
54
55
# File 'lib/graphm/render/path.rb', line 53

def render_node node
	return node.name
end