Class: UML::Graphviz::Graph

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(type, name) ⇒ Graph

Returns a new instance of Graph.



21
22
23
24
25
26
27
28
29
30
# File 'lib/uml/graphviz_helper.rb', line 21

def initialize(type, name)
  @name = name
  @type = type
  @subgraphs = {}
  @nodes = {}
  @edges = {}
  @default_graph_attributes = Attributes.new
  @default_node_attributes = Attributes.new
  @default_edge_attributes = Attributes.new
end

Instance Attribute Details

#default_edge_attributesObject (readonly)

Returns the value of attribute default_edge_attributes.



17
18
19
# File 'lib/uml/graphviz_helper.rb', line 17

def default_edge_attributes
  @default_edge_attributes
end

#default_graph_attributesObject (readonly)

Returns the value of attribute default_graph_attributes.



17
18
19
# File 'lib/uml/graphviz_helper.rb', line 17

def default_graph_attributes
  @default_graph_attributes
end

#default_node_attributesObject (readonly)

Returns the value of attribute default_node_attributes.



17
18
19
# File 'lib/uml/graphviz_helper.rb', line 17

def default_node_attributes
  @default_node_attributes
end

#edgesObject

Returns the value of attribute edges.



16
17
18
# File 'lib/uml/graphviz_helper.rb', line 16

def edges
  @edges
end

#nodesObject

Returns the value of attribute nodes.



16
17
18
# File 'lib/uml/graphviz_helper.rb', line 16

def nodes
  @nodes
end

#subgraphsObject

Returns the value of attribute subgraphs.



16
17
18
# File 'lib/uml/graphviz_helper.rb', line 16

def subgraphs
  @subgraphs
end

Class Method Details

.name_to_id(object) ⇒ Object



48
49
50
# File 'lib/uml/graphviz_helper.rb', line 48

def self.name_to_id(object)
  '_' << object.to_s.gsub(/::/, '_')
end

Instance Method Details

#name_to_id(object) ⇒ Object



44
45
46
# File 'lib/uml/graphviz_helper.rb', line 44

def name_to_id(object)
  self.class.name_to_id object
end

#to_dot(indent = 0) ⇒ Object



32
33
34
35
36
37
38
39
40
41
42
# File 'lib/uml/graphviz_helper.rb', line 32

def to_dot(indent = 0)
  result = ''
  result << '  ' * indent << "#{@type} #{@name} {\n"
  result << '  ' * (indent + 1) << "graph #{@default_graph_attributes.to_dot};\n" unless @default_graph_attributes.empty?
  result << '  ' * (indent + 1) << "node #{@default_node_attributes.to_dot};\n" unless @default_node_attributes.empty?
  result << '  ' * (indent + 1) << "edge #{@default_edge_attributes.to_dot};\n" unless @default_edge_attributes.empty?
  result << collection_to_dot(@subgraphs.values, indent)
  result << collection_to_dot(@nodes.values, indent)
  result << collection_to_dot(@edges.values, indent)
  result << '  ' * indent << '}'
end