class Gremlin2Dot::GraphBuilder
Public Class Methods
build(results)
click to toggle source
# File lib/gremlin2dot/graph_builder.rb, line 7 def self.build(results) self.new().build(results) end
new()
click to toggle source
# File lib/gremlin2dot/graph_builder.rb, line 11 def initialize @seen = Set.new @g = GraphViz.new("G") end
Public Instance Methods
build(unmangled_data)
click to toggle source
# File lib/gremlin2dot/graph_builder.rb, line 16 def build(unmangled_data) add_thing unmangled_data['result']['data'] @g end
Private Instance Methods
add_edge(edge)
click to toggle source
# File lib/gremlin2dot/graph_builder.rb, line 54 def add_edge(edge) label = edge.id.to_s + "\n" + edge.label + edge.properties.entries.sort_by(&:first).map {|k, v| "\n#{k}=#{v}" }.join("") @g.add_edges(edge.outV.to_s, edge.inV.to_s, label: label) end
add_node(node)
click to toggle source
# File lib/gremlin2dot/graph_builder.rb, line 49 def add_node(node) label = node.id.to_s + "\n" + node.label + node.properties.entries.sort_by(&:first).map {|k, v| "\n#{k}=#{v.first}" }.join("") @g.add_nodes(node.id.to_s, label: label) end
add_thing(thing)
click to toggle source
# File lib/gremlin2dot/graph_builder.rb, line 23 def add_thing(thing) # $stderr.puts "add_thing #{thing.class} #{thing}" case thing when Vertex once_only(thing.id) { add_node thing } when Edge once_only(thing.id) { add_edge thing } when Tree add_thing thing.key thing.items.each {|child| add_thing child} when Path thing.objects.each {|child| add_thing child} when Array thing.each {|child| add_thing child} else $stderr.puts "Not adding #{thing.class} to the graph" end end
once_only(id) { || ... }
click to toggle source
# File lib/gremlin2dot/graph_builder.rb, line 42 def once_only(id) unless @seen.include? id yield @seen << id end end