Class JavaClass::Dependencies::GraphmlSerializer
In: lib/javaclass/dependencies/graphml_serializer.rb
Parent: Object

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

Methods

Included Modules

REXML

Public Class methods

Create a serializer with options hash:

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

[Source]

# File lib/javaclass/dependencies/graphml_serializer.rb, line 17
      def initialize(options = { :edges => :with_counts })
        @options = options
      end

Public Instance methods

Add the node as XML to the container .

[Source]

# 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

Return an XML document of the GraphML serialized graph .

[Source]

# 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 the graph to filename .

[Source]

# 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

[Validate]