Class: JavaClass::Dependencies::GraphmlSerializer

Inherits:
Object
  • Object
show all
Includes:
REXML
Defined in:
lib/javaclass/dependencies/graphml_serializer.rb

Overview

Serializes a Graph of Node to GraphML (XML). To see the graph, use yED, www.yworks.com/en/products_yed_about.html to

  • load the graphml file.

  • Then select all nodes and apply Tools/Fit Node to Label.

  • Finally apply the Layout/Hierarchical or maybe Layout/Organic/Smart.

Author

Peter Kofler

Instance Method Summary collapse

Constructor Details

#initialize(options = { :edges => :with_counts }) ⇒ GraphmlSerializer

Create a serializer with options hash:

edges

how to chart edge labes, either :no_text or :with_counts



17
18
19
# File 'lib/javaclass/dependencies/graphml_serializer.rb', line 17

def initialize(options = { :edges => :with_counts })
  @options = options
end

Instance Method Details

#add_node_as_xml(container, node) ⇒ Object

Add the node as XML to the container .



57
58
59
60
61
62
63
# File 'lib/javaclass/dependencies/graphml_serializer.rb', line 57

def add_node_as_xml(container, node)
  add_node_element(container, node)
    
  node.dependencies.keys.each do |dep|
    add_edge_element(container, node, dep)
  end
end

#graph_to_xml(graph) ⇒ Object

Return an XML document of the GraphML serialized graph .



31
32
33
34
35
36
# File 'lib/javaclass/dependencies/graphml_serializer.rb', line 31

def graph_to_xml(graph)
  doc = create_xml_doc
  container = add_graph_element(doc)
  graph.to_a.each { |node| add_node_as_xml(container, node) }
  doc
end

#save(filename, graph) ⇒ Object

Save the graph to filename .



22
23
24
25
26
27
28
# File 'lib/javaclass/dependencies/graphml_serializer.rb', line 22

def save(filename, graph)
  File.open(filename + '.graphml', 'w') do |f|
    doc = graph_to_xml(graph)
    doc.write(out_string = '', 2)
    f.print out_string
  end
end