Class: PacerXml::BuildGraph
Instance Attribute Summary
Attributes inherited from GraphVisitor
#depth, #documents, #graph, #html, #rename, #skip, #with_body
Instance Method Summary
collapse
#build, build_rename, #initialize, #level, #skip?, #tell, #visit_edge_fields, #visit_vertex_fields, #with_body?
Instance Method Details
#visit_element(e) ⇒ Object
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
|
# File 'lib/pacer-xml/build_graph.rb', line 98
def visit_element(e)
return nil if skip? e
level do
vertex = graph.create_vertex visit_vertex_fields(e)
e.one_rels.each do |rel|
visit_one_rel e, vertex, rel
end
e.many_rels.each do |rel|
visit_many_rels e, vertex, rel
end
if block_given?
yield vertex
else
vertex
end
end
end
|
#visit_many_rel(from_e, from, rel, to_e, attrs) ⇒ Object
135
136
137
138
139
140
|
# File 'lib/pacer-xml/build_graph.rb', line 135
def visit_many_rel(from_e, from, rel, to_e, attrs)
to = visit_element(to_e)
if from and to
graph.create_edge nil, from, to, rename[rel.name], attrs
end
end
|
#visit_many_rels(from_e, from, rel) ⇒ Object
123
124
125
126
127
128
129
130
131
132
133
|
# File 'lib/pacer-xml/build_graph.rb', line 123
def visit_many_rels(from_e, from, rel)
return nil if skip? rel
level do
attrs = visit_edge_fields rel
rel[:body] = rel.inner_text if with_body? rel
attrs.delete :type
rel.contained_rels.map do |to_e|
visit_many_rel(from_e, from, rel, to_e, attrs)
end
end
end
|
#visit_one_rel(e, from, rel) ⇒ Object
116
117
118
119
120
121
|
# File 'lib/pacer-xml/build_graph.rb', line 116
def visit_one_rel(e, from, rel)
to = visit_element(rel)
if from and to
graph.create_edge nil, from, to, rename[rel.name]
end
end
|