class Mementus::Graph

Public Instance Methods

inspect() click to toggle source
# File lib/extensions/mementus.rb, line 42
def inspect
  "<Mementus::Graph @structure=#{@structure.inspect} " +
    "nodes_count=#{nodes_count} edges_count=#{edges_count}>"
end
to_dot() click to toggle source
# 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