Class: RGL::DOT::Node

### Home Classes Methods

### In Files

- lib/rgl/rdot.rb

### Parent

RGL::DOT::Element

### Methods

- ::new
- #to_s

### Class/Module Index

Quicksearch

- RGL
- RGL::AdjacencyGraph
- RGL::BFSIterator
- RGL::BellmanFordAlgorithm
- RGL::BellmanFordVisitor
- RGL::BidirectionalGraph
- RGL::BipartiteBFSIterator
- RGL::DFSIterator
- RGL::DFSVisitor
- RGL::DOT
- RGL::DOT::Digraph
- RGL::DOT::DirectedEdge
- RGL::DOT::Edge
- RGL::DOT::Element
- RGL::DOT::Graph
- RGL::DOT::Node
- RGL::DOT::Port
- RGL::DOT::Subgraph
- RGL::DijkstraAlgorithm
- RGL::DijkstraVisitor
- RGL::DirectedAdjacencyGraph
- RGL::Edge
- RGL::Edge::DirectedEdge
- RGL::Edge::UnDirectedEdge
- RGL::EdgePropertiesMap
- RGL::EdmondsKarpAlgorithm
- RGL::EdmondsKarpAlgorithm::EdmondsKarpBFSIterator
- RGL::Graph
- RGL::Graph::TarjanSccVisitor
- RGL::GraphIterator
- RGL::GraphVisitor
- RGL::GraphVisitor::ClassMethods
- RGL::GraphVisitor::DistanceMapSupport
- RGL::ImplicitGraph
- RGL::MutableGraph
- RGL::MutableGraph::MutableGraphParser
- RGL::NoEdgeError
- RGL::NoVertexError
- RGL::NonNegativeEdgePropertiesMap
- RGL::NotDirectedError
- RGL::NotUndirectedError
- RGL::PrimAlgorithm
- RGL::TopsortIterator
- Enumerable
- Object

No matching classes.

# RGL::DOT::Node

A node representation. Edges are drawn between nodes. The rendering of a node depends upon the options set for it.

### Attributes

ports[RW]

### Public Class Methods

new(params = {}, option_list = NODE_OPTS) click to toggle source

Creates a new Node with the params Hash providing settings for all node options. The option_list parameter restricts those options to the list of valid names it contains. The exception to this is the ports option which, if specified, must be an Enumerable containing a list of ports.

    # File lib/rgl/rdot.rb, line 247
    def initialize(params = {}, option_list = NODE_OPTS)
      super(params, option_list)
      @ports = params['ports'] ? params['ports'] : []
    end

### Public Instance Methods

to_s(leader = '', indent = ' ') click to toggle source

Returns a string representation of this node which is consumable by the graphviz tools `dot` and `neato`. The leader parameter is used to indent every line of the returned string, and the indent parameter is used to additionally indent nested items.

    # File lib/rgl/rdot.rb, line 257
    def to_s(leader = '', indent = '    ')
      label_option = nil

      if @options['shape'] =~ /^M?record$/ && !@ports.empty?
        # Ignore the given label option in this case since the ports should each
        # provide their own name/label.
        label_option = leader + indent + "#{quote_ID('label')} = #{quote_ID(@ports.collect { |port| port.to_s }.join(" | "))}"
      elsif @options['label']
        # Otherwise, use the label when given one.
        label_option = leader + indent + "#{quote_ID('label')} = #{quote_label(@options['label'])}"
      end

      # Convert all the options except `label' and options with nil values
      # straight into name = value pairs. Then toss out any resulting nil
      # entries in the final array.
      stringified_options = @options.collect do |name, val|
        unless name == 'label' || val.nil?
          leader + indent + "#{quote_ID(name)} = #{quote_ID(val)}"
        end
      end.compact

      # Append the specially computed label option.
      stringified_options.push(label_option) unless label_option.nil?

      # Join them all together.
      stringified_options = stringified_options.join(",\n")

      # Put it all together into a single string with indentation and return the
      # result.
      if stringified_options.empty?
        leader + quote_ID(@name) unless @name.nil?
      else
        leader + (@name.nil? ? '' : quote_ID(@name) + " ") + "[\n" +
            stringified_options + "\n" +
            leader + "]"
      end
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.