lib/graphviz/graphml.rb in ruby-graphviz-0.9.21 vs lib/graphviz/graphml.rb in ruby-graphviz-1.0.0
- old
+ new
@@ -19,10 +19,12 @@
require 'rexml/document'
class GraphViz
class GraphML
attr_reader :attributs
+
+ # The GraphViz object
attr_accessor :graph
DEST = {
'node' => [:nodes],
'edge' => [:edges],
@@ -33,10 +35,13 @@
GTYPE = {
'directed' => :digraph,
'undirected' => :graph
}
+ #
+ # Create a new GraphViz object from a GraphML file of string
+ #
def initialize( file_or_str )
data = ((File.file?( file_or_str )) ? File::new(file_or_str) : file_or_str)
@xmlDoc = REXML::Document::new( data )
@attributs = {
:nodes => {},
@@ -50,29 +55,29 @@
@current_graph = nil
parse( @xmlDoc.root )
end
- def parse( node )
+ def parse( node ) #:nodoc:
#begin
send( node.name.to_sym, node )
#rescue NoMethodError => e
# raise "ERROR node #{node.name} can be root"
#end
end
- def graphml( node )
+ def graphml( node ) #:nodoc:
node.each_element( ) do |child|
#begin
send( "graphml_#{child.name}".to_sym, child )
#rescue NoMethodError => e
# raise "ERROR node #{child.name} can be child of graphml"
#end
end
end
- def graphml_key( node )
+ def graphml_key( node ) #:nodoc:
id = node.attributes['id']
@current_attr = {
:name => node.attributes['attr.name'],
:type => node.attributes['attr.type']
}
@@ -89,15 +94,15 @@
end
@current_attr = nil
end
- def graphml_key_default( node )
+ def graphml_key_default( node ) #:nodoc:
@current_attr[:default] = node.texts().to_s
end
- def graphml_graph( node )
+ def graphml_graph( node ) #:nodoc:
@current_node = nil
if @current_graph.nil?
@graph = GraphViz.new( node.attributes['id'], :type => GTYPE[node.attributes['edgedefault']] )
@current_graph = @graph
@@ -126,15 +131,15 @@
end
@current_graph = previous_graph
end
- def graphml_graph_data( node )
+ def graphml_graph_data( node ) #:nodoc:
@current_graph[@attributs[:graphs][node.attributes['key']][:name]] = node.texts().to_s
end
- def graphml_graph_node( node )
+ def graphml_graph_node( node ) #:nodoc:
@current_node = {}
node.each_element( ) do |child|
case child.name
when "graph"
@@ -156,26 +161,26 @@
end
@current_node = nil
end
- def graphml_graph_node_data( node )
+ def graphml_graph_node_data( node ) #:nodoc:
@current_node[@attributs[:nodes][node.attributes['key']][:name]] = node.texts().to_s
end
- def graphml_graph_node_port( node )
+ def graphml_graph_node_port( node ) #:nodoc:
@current_node[:shape] = :record
port = node.attributes['name']
if @current_node[:label]
label = @current_node[:label].gsub( "{", "" ).gsub( "}", "" )
@current_node[:label] = "#{label}|<#{port}> #{port}"
else
@current_node[:label] = "<#{port}> #{port}"
end
end
- def graphml_graph_edge( node )
+ def graphml_graph_edge( node ) #:nodoc:
source = node.attributes['source']
source = {source => node.attributes['sourceport']} if node.attributes['sourceport']
target = node.attributes['target']
target = {target => node.attributes['targetport']} if node.attributes['targetport']
@@ -190,14 +195,14 @@
end
@current_edge = nil
end
- def graphml_graph_edge_data( node )
+ def graphml_graph_edge_data( node ) #:nodoc:
@current_edge[@attributs[:edges][node.attributes['key']][:name]] = node.texts().to_s
end
- def graphml_graph_hyperedge( node )
+ def graphml_graph_hyperedge( node ) #:nodoc:
list = []
node.each_element( ) do |child|
if child.name == "endpoint"
if child.attributes['port']
\ No newline at end of file