Class: GraphvizR::Node

Inherits:
Object
  • Object
show all
Defined in:
lib/graphviz_r.rb

Overview

This represents graphviz node.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, port, dot) ⇒ Node

Returns a new instance of Node.



134
135
136
137
138
139
140
141
142
143
# File 'lib/graphviz_r.rb', line 134

def initialize(name, port, dot)
  @name = name
  @port = port || []
  @dot = dot
  @prop = {}

  if !@port.empty? and @port[0].is_a? Array and @port[0][0].is_a? Hash
    @dot[@name] = @port[0][0]
  end
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



132
133
134
# File 'lib/graphviz_r.rb', line 132

def name
  @name
end

#propObject (readonly)

Returns the value of attribute prop.



132
133
134
# File 'lib/graphviz_r.rb', line 132

def prop
  @prop
end

Instance Method Details

#-(node) ⇒ Object

This generates a undirected edge from this node to given node.



152
153
154
155
# File 'lib/graphviz_r.rb', line 152

def -(node)
  @dot.undirected!
  add_edge_on_dot node
end

#<=>(other) ⇒ Object



170
171
172
# File 'lib/graphviz_r.rb', line 170

def <=>(other)
  @name <=> other.name
end

#>>(node) ⇒ Object

This generates a directed edge from this node to given node.



146
147
148
149
# File 'lib/graphviz_r.rb', line 146

def >>(node)
  @dot.directed!
  add_edge_on_dot node
end

#[](prop) ⇒ Object



164
165
166
167
168
# File 'lib/graphviz_r.rb', line 164

def [](prop)
  @dot[@name] = prop
  @prop.merge! prop
  self
end

#add_edge_on_dot(node) ⇒ Object



157
158
159
160
161
162
# File 'lib/graphviz_r.rb', line 157

def add_edge_on_dot(node)
  prop = @prop.merge node.prop
  edge = Edge.new(self, node, @dot, prop)
  @dot.add_edge edge
  edge
end

#to_dotObject



178
179
180
181
182
# File 'lib/graphviz_r.rb', line 178

def to_dot
  name = @port.dup
  name.unshift @name
  name.map{|e| e.to_dot}.join(':')
end

#to_symObject



174
175
176
# File 'lib/graphviz_r.rb', line 174

def to_sym
  self
end