Class: Graphshaper::DotAdapter

Inherits:
Object
  • Object
show all
Defined in:
lib/graphshaper/adapters/dot_adapter.rb

Instance Method Summary collapse

Constructor Details

#initialize(output_file) ⇒ DotAdapter

Returns a new instance of DotAdapter.


3
4
5
6
# File 'lib/graphshaper/adapters/dot_adapter.rb', line 3

def initialize(output_file)
  @output_file = output_file
  @output_file << "digraph genereated_graph { \n  rankdir=LR;\n  node [shape = circle];\n  edge [dir=none];\n"
end

Instance Method Details

#add_edge(edge_id, in_id, out_id) ⇒ Object


8
9
10
# File 'lib/graphshaper/adapters/dot_adapter.rb', line 8

def add_edge(edge_id, in_id, out_id)
  @output_file << "  #{in_id} -> #{out_id} [ label = \"#{edge_id}\" ];\n"
end

#add_vertex(vertex_id) ⇒ Object


12
13
14
# File 'lib/graphshaper/adapters/dot_adapter.rb', line 12

def add_vertex(vertex_id)
  @output_file << "  #{vertex_id};\n"
end

#closeObject


16
17
18
19
# File 'lib/graphshaper/adapters/dot_adapter.rb', line 16

def close
  @output_file << "}"
  @output_file.close
end