Class: GraphViz::DOTScriptData

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(type = nil) ⇒ DOTScriptData

Returns a new instance of DOTScriptData.



6
7
8
9
10
# File 'lib/graphviz/dot_script.rb', line 6

def initialize(type = nil)
  @data = []
  @separator = ""
  @type = type
end

Instance Attribute Details

#typeObject

Returns the value of attribute type.



5
6
7
# File 'lib/graphviz/dot_script.rb', line 5

def type
  @type
end

Instance Method Details

#add_attribute(name, value) ⇒ Object



17
18
19
20
# File 'lib/graphviz/dot_script.rb', line 17

def add_attribute(name, value)
  @data << @separator << name << " = " << value
  @separator = determine_separator
end

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



12
13
14
# File 'lib/graphviz/dot_script.rb', line 12

def append(data)
  @data << data
end

#empty?Boolean

Returns:

  • (Boolean)


32
33
34
# File 'lib/graphviz/dot_script.rb', line 32

def empty?
  @data.empty?
end

#to_strObject Also known as: to_s



22
23
24
25
26
27
28
29
# 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