Class: GraphViz::DOTScript

Inherits:
Object show all
Extended by:
Forwardable
Defined in:
lib/graphviz/dot_script.rb

Instance Method Summary collapse

Constructor Details

#initializeDOTScript

Returns a new instance of DOTScript.



53
54
55
# File 'lib/graphviz/dot_script.rb', line 53

def initialize
  @script = ''
end

Instance Method Details

#add_type(type, data) ⇒ Object



74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
# File 'lib/graphviz/dot_script.rb', line 74

def add_type(type, data)
  return self if data.empty?

  case type
  when "graph_attr"
    append_statement("  " + data)
  when "node_attr"
    append_statement("  node [" + data + "]")
  when "edge_attr"
    append_statement("  edge [" + data + "]")
  else
    raise ArgumentError,
      "Unknown type: #{type}." <<
      "Possible: 'graph_attr','node_attr','edge_attr'"
  end

  self
end

#append(line) ⇒ Object Also known as: <<



57
58
59
60
61
# File 'lib/graphviz/dot_script.rb', line 57

def append(line)
  @script << assure_ends_with(line.to_s,"\n")

  self
end

#make_subgraph(name) ⇒ Object



70
71
72
# File 'lib/graphviz/dot_script.rb', line 70

def make_subgraph(name)
  prepend(assure_ends_with("subgraph #{name}"," {"))
end

#prepend(line) ⇒ Object



64
65
66
67
68
# File 'lib/graphviz/dot_script.rb', line 64

def prepend(line)
  @script = assure_ends_with(line.to_s,"\n") + @script

  self
end

#to_strObject Also known as: to_s



93
94
95
# File 'lib/graphviz/dot_script.rb', line 93

def to_str
  @script
end