Class: Mementus::Graph

Inherits:
Object
  • Object
show all
Defined in:
lib/extensions/mementus.rb

Instance Method Summary collapse

Instance Method Details

#inspectObject



42
43
44
45
# File 'lib/extensions/mementus.rb', line 42

def inspect
  "<Mementus::Graph @structure=#{@structure.inspect} " +
    "nodes_count=#{nodes_count} edges_count=#{edges_count}>"
end

#to_dotObject



47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/extensions/mementus.rb', line 47

def to_dot
  statements = []

  nodes.each do |node|
    label = if node.props.key?(:type)
      "#{node.label}: #{node.props[:type]}:#{node.props[:resource].name}"
    elsif node.props.key?(:name)
      "#{node.label}: #{node.props[:name]}"
    else
      node.label
    end

    statements << "#{node.id} [label=\"#{label}\"]"
  end

  edges.each do |edge|
    statements << "#{edge.from.id} -> #{edge.to.id} [label=\"#{edge.label}\"];"
  end

  "digraph {\n#{statements.join("\n")}\n}"
end