Class: GraphvizR::Edge

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

Overview

This represents a graphviz edge.

Instance Method Summary collapse

Constructor Details

#initialize(from, to, parent, arrow = '->') ⇒ Edge

Returns a new instance of Edge.



298
299
300
301
302
303
304
305
306
307
308
309
310
# File 'lib/graphviz_r.rb', line 298

def initialize(from, to, parent, arrow='->')
  @attributes = {}
  @nodes = [from, to]
  @arrow = arrow
  @parent = parent
  (from.is_a?(Array) ? from : [from]).size.times do
    @parent.statements.pop
  end
  (to.is_a?(Array) ? to : [to]).size.times do
    @parent.statements.pop
  end
  @parent.statements << self
end

Instance Method Details

#-(node) ⇒ Object

consequent undirected edge



328
329
330
331
332
333
334
335
# File 'lib/graphviz_r.rb', line 328

def -(node)
  @parent.to_graph
  (node.is_a?(Array) ? node : [node]).size.times do
    @parent.statements.pop
  end
  @nodes << node
  self
end

#>>(node) ⇒ Object

consequent directed edge



318
319
320
321
322
323
324
325
# File 'lib/graphviz_r.rb', line 318

def >>(node)
  @parent.to_digraph
  (node.is_a?(Array) ? node : [node]).size.times do
    @parent.statements.pop
  end
  @nodes << node
  self
end

#[](attributes) ⇒ Object

set attributes for the edge



313
314
315
# File 'lib/graphviz_r.rb', line 313

def [](attributes)
  @attributes = attributes
end

#to_dot(indent) ⇒ Object

to dot



338
339
340
341
342
# File 'lib/graphviz_r.rb', line 338

def to_dot(indent)
  edge = @nodes.map{|e| e.is_a?(Array) ? e.to_dot : e.to_s}.join(" #{@arrow} ")
  attributes = @attributes.empty? ? '' : ' ' + @attributes.to_dot
  "#{INDENT_UNIT * indent}#{edge}#{attributes};\n"
end