Class: RGL::MutableGraph::MutableGraphParser

Inherits:
Object
  • Object
show all
Includes:
REXML::StreamListener
Defined in:
lib/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.



31
32
33
34
# File 'lib/rgl/graphxml.rb', line 31

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.



39
40
41
42
43
44
45
46
# File 'lib/rgl/graphxml.rb', line 39

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