Class: DotR::Node

Inherits:
Object
  • Object
show all
Includes:
Styled
Defined in:
lib/dotr.rb

Overview

Represents a node in a digraph. Instances of this class are created by calling Digraph#node.

Specify styles on this object by setting instance attributes. Possible attributes include ‘label’ and ‘shape’; the attribute names and possible values correspond to the style attributes described in the ‘dot’ manual.

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Styled

#method_missing, #style

Constructor Details

#initialize(name, style = {}) {|_self| ... } ⇒ Node

:nodoc:

Yields:

  • (_self)

Yield Parameters:

  • _self (DotR::Node)

    the object that the method was called on



128
129
130
131
132
133
134
# File 'lib/dotr.rb', line 128

def initialize(name, style={}, &block)  #:nodoc:
  @name = name
  @connections = []
  self.label = name
  style_attrs.update(style)
  yield self if block
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class DotR::Styled

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



126
127
128
# File 'lib/dotr.rb', line 126

def name
  @name
end

Instance Method Details

#connection(other_node_name, style = {}, &block) ⇒ Object



136
137
138
# File 'lib/dotr.rb', line 136

def connection(other_node_name, style={}, &block)
  @connections << Connection.new(self.name, other_node_name, style, &block)
end

#render_to(output_lines, indent) ⇒ Object

:nodoc:



140
141
142
143
# File 'lib/dotr.rb', line 140

def render_to(output_lines, indent)  #:nodoc:
  output_lines << "#{indent}\"#{self.name}\"" + style + ";"
  @connections.each { |c| c.render_to(output_lines, indent) }
end