class GraphViz::DOTScriptData

Attributes

type[RW]

Public Class Methods

new(type = nil) click to toggle source
# File lib/graphviz/dot_script.rb, line 6
def initialize(type = nil)
  @data = []
  @separator = ""
  @type = type
end

Public Instance Methods

<<(data)
Alias for: append
add_attribute(name, value) click to toggle source
# File lib/graphviz/dot_script.rb, line 17
def add_attribute(name, value)
  @data << @separator << name << " = " << value
  @separator = determine_separator
end
append(data) click to toggle source
# File lib/graphviz/dot_script.rb, line 12
def append(data)
  @data << data
end
Also aliased as: <<
empty?() click to toggle source
# File lib/graphviz/dot_script.rb, line 32
def empty?
  @data.empty?
end
to_s()
Alias for: to_str
to_str() click to toggle source
# File lib/graphviz/dot_script.rb, line 22
def to_str
  case @type
    when "graph_attr" then "#{@data.join}#{@separator}"
    when "node_attr" then "node[#{@data.join(' ')}];"
    when "edge_attr" then "edge[#{@data.join(' ')}];"
    else raise ArgumentError, "Wrong type: #{@type}."
  end
end
Also aliased as: to_s

Private Instance Methods

determine_separator() click to toggle source
# File lib/graphviz/dot_script.rb, line 38
def determine_separator
  case @type
    when "graph_attr"             then ";\n"
    when "node_attr", "edge_attr" then ","
    else raise ArgumentError, "Wrong type: #{@type}."
  end
end