### Home Classes Methods

### In Files

- lib/graphviz/graphml.rb

### Parent

Object

### Methods

- ::new
- #graphml
- #graphml_graph
- #graphml_graph_data
- #graphml_graph_edge
- #graphml_graph_edge_data
- #graphml_graph_hyperedge
- #graphml_graph_node
- #graphml_graph_node_data
- #graphml_graph_node_port
- #graphml_key
- #graphml_key_default
- #parse

### Files

- AUTHORS
- COPYING
- README.rdoc

### Class/Module Index

Quicksearch

- GraphViz
- GraphViz::Attrs
- GraphViz::Edge
- GraphViz::Elements
- GraphViz::Ext
- GraphViz::FamilyTree
- GraphViz::FamilyTree::Couple
- GraphViz::FamilyTree::Generation
- GraphViz::FamilyTree::Person
- GraphViz::FamilyTree::Sibling
- GraphViz::GraphML
- GraphViz::Math
- GraphViz::Math::CoordinateError
- GraphViz::Math::Matrix
- GraphViz::Math::ValueError
- GraphViz::Node
- GraphViz::Theory
- GraphViz::Types
- GraphViz::Types::Common
- GraphViz::Types::EscString
- GraphViz::Types::GvDouble
- GraphViz::Types::HtmlString
- GraphViz::Types::LblString
- GraphViz::XML
- Constants
- GVUtils
- Hash
- Object
- String

No matching classes.

# GraphViz::GraphML

### Constants

DEST
GTYPE

### Attributes

attributs[R]
graph[RW]

### Public Class Methods

new( file_or_str ) click to toggle source

    # File lib/graphviz/graphml.rb, line 38
    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 => {},
        :edges => {},
        :graphs => {}
      }
      @graph = nil
      @current_attr = nil
      @current_node = nil
      @current_edge = nil
      @current_graph = nil

      parse( @xmlDoc.root )
    end

### Public Instance Methods

graphml( node ) click to toggle source

    # File lib/graphviz/graphml.rb, line 63
    def graphml( node )
      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

graphml_graph( node ) click to toggle source

    # File lib/graphviz/graphml.rb, line 98
    def graphml_graph( node )
      @current_node = nil

      if @current_graph.nil?
        @graph = GraphViz.new( node.attributes['id'], :type => GTYPE[node.attributes['edgedefault']] )
        @current_graph = @graph
        previous_graph = @graph
      else
        previous_graph = @current_graph
        @current_graph = previous_graph.add_graph( node.attributes['id'] )
      end

      @attributs[:graphs].each do |id, data|
        @current_graph.graph[data[:name]] = data[:default] if data.has_key?(:default)
      end
      @attributs[:nodes].each do |id, data|
        @current_graph.node[data[:name]] = data[:default] if data.has_key?(:default)
      end
      @attributs[:edges].each do |id, data|
        @current_graph.edge[data[:name]] = data[:default] if data.has_key?(:default)
      end

      node.each_element( ) do |child|
        #begin
          send( "graphml_graph_#{child.name}".to_sym, child )
        #rescue NoMethodError => e
        #  raise "ERROR node #{child.name} can be child of graphml"
        #end
      end

      @current_graph = previous_graph
    end

graphml_graph_data( node ) click to toggle source

    # File lib/graphviz/graphml.rb, line 131
    def graphml_graph_data( node )
      @current_graph[@attributs[:graphs][node.attributes['key']][:name]] = node.texts().to_s
    end

graphml_graph_edge( node ) click to toggle source

    # File lib/graphviz/graphml.rb, line 176
    def graphml_graph_edge( node )
      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']

      @current_edge = @current_graph.add_edge( source, target )

      node.each_element( ) do |child|
        #begin
          send( "graphml_graph_edge_#{child.name}".to_sym, child )
        #rescue NoMethodError => e
        #  raise "ERROR node #{child.name} can be child of graphml"
        #end
      end

      @current_edge = nil
    end

graphml_graph_edge_data( node ) click to toggle source

    # File lib/graphviz/graphml.rb, line 195
    def graphml_graph_edge_data( node )
      @current_edge[@attributs[:edges][node.attributes['key']][:name]] = node.texts().to_s
    end

graphml_graph_hyperedge( node ) click to toggle source

    # File lib/graphviz/graphml.rb, line 199
    def graphml_graph_hyperedge( node )
      list = []

      node.each_element( ) do |child|
        if child.name == "endpoint"
          if child.attributes['port']
            list << { child.attributes['node'] => child.attributes['port'] }
          else
            list << child.attributes['node']
          end
        end
      end

      list.each { |s|
        list.each { |t|
          @current_graph.add_edge( s, t ) unless s == t
        }
      }
    end

graphml_graph_node( node ) click to toggle source

    # File lib/graphviz/graphml.rb, line 135
    def graphml_graph_node( node )
      @current_node = {}

      node.each_element( ) do |child|
        case child.name
        when "graph"
          graphml_graph( child )
        else
          begin
            send( "graphml_graph_node_#{child.name}".to_sym, child )
          rescue NoMethodError => e
            raise "ERROR node #{child.name} can be child of graphml"
          end
        end
      end

      unless @current_node.nil?
        node = @current_graph.add_node( node.attributes['id'] )
        @current_node.each do |k, v|
          node[k] = v
        end
      end

      @current_node = nil
    end

graphml_graph_node_data( node ) click to toggle source

    # File lib/graphviz/graphml.rb, line 161
    def graphml_graph_node_data( node )
      @current_node[@attributs[:nodes][node.attributes['key']][:name]] = node.texts().to_s
    end

graphml_graph_node_port( node ) click to toggle source

    # File lib/graphviz/graphml.rb, line 165
    def graphml_graph_node_port( node )
      @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

graphml_key( node ) click to toggle source

    # File lib/graphviz/graphml.rb, line 73
    def graphml_key( node )
      id = node.attributes['id']
      @current_attr = {
        :name => node.attributes['attr.name'],
        :type => node.attributes['attr.type']
      }
      DEST[node.attributes['for']].each do |d|
        @attributs[d][id] = @current_attr
      end

      node.each_element( ) do |child|
        begin
          send( "graphml_key_#{child.name}".to_sym, child )
        rescue NoMethodError => e
          raise "ERROR node #{child.name} can be child of graphml"
        end
      end

      @current_attr = nil
    end

graphml_key_default( node ) click to toggle source

    # File lib/graphviz/graphml.rb, line 94
    def graphml_key_default( node )
      @current_attr[:default] = node.texts().to_s
    end

parse( node ) click to toggle source

    # File lib/graphviz/graphml.rb, line 55
    def parse( node )
      #begin
        send( node.name.to_sym, node )
      #rescue NoMethodError => e
      #  raise "ERROR node #{node.name} can be root"
      #end
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.