Class: RGL::MutableGraph::MutableGraphParser

Inherits:
Object
  • Object
show all
Includes:
REXML::StreamListener
Defined in:
lib/laser/third_party/rgl/graphxml.rb

Overview

Used to parse a subset of GraphML into an RGL graph implementation.

Instance Method Summary collapse

Constructor Details

#initialize(graph) ⇒ MutableGraphParser

First resets graph to be empty and stores a reference for use with #tag_start.



26
27
28
29
# File 'lib/laser/third_party/rgl/graphxml.rb', line 26

def initialize (graph)
  @graph = graph
  @graph.remove_vertices(@graph.vertices)
end

Instance Method Details

#tag_start(name, attrs) ⇒ Object

Processes incoming edge and node elements from GraphML in order to populate the graph given to #new.



33
34
35
36
37
38
39
40
# File 'lib/laser/third_party/rgl/graphxml.rb', line 33

def tag_start (name, attrs)
  case name
  when 'edge'
    @graph.add_edge(attrs['source'], attrs['target'])
  when 'node'
    @graph.add_vertex(attrs['id'])
  end
end