Class: PacerXml::BuildGraph

Inherits:
GraphVisitor show all
Defined in:
lib/pacer-xml/build_graph.rb

Direct Known Subclasses

BuildGraphCached

Instance Attribute Summary

Attributes inherited from GraphVisitor

#depth, #documents, #graph, #html, #rename, #skip

Instance Method Summary collapse

Methods inherited from GraphVisitor

#build, build_rename, #initialize, #level, #skip?, #tell, #visit_edge_fields, #visit_vertex_fields

Constructor Details

This class inherits a constructor from PacerXml::GraphVisitor

Instance Method Details

#visit_element(e) ⇒ Object



90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
# File 'lib/pacer-xml/build_graph.rb', line 90

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



126
127
128
129
130
131
# File 'lib/pacer-xml/build_graph.rb', line 126

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



115
116
117
118
119
120
121
122
123
124
# File 'lib/pacer-xml/build_graph.rb', line 115

def visit_many_rels(from_e, from, rel)
  return nil if skip? rel
  level do
    attrs = visit_edge_fields 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



108
109
110
111
112
113
# File 'lib/pacer-xml/build_graph.rb', line 108

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