X-Git-Url: https://git.njae.me.uk/?a=blobdiff_plain;f=lib%2Fgraph.njae%2Fvertex.rb;h=def0b66d79a81ff2b0348655d1459cab1720aefe;hb=07acbb1582f12f3dcde0351277cc42a36e61e87b;hp=aeabe30559be5f1f0a4cf1acf19a7607ff6a1249;hpb=804c1d3850e599aea8cb3258d1a875be148a3b30;p=graph.njae.git diff --git a/lib/graph.njae/vertex.rb b/lib/graph.njae/vertex.rb index aeabe30..def0b66 100644 --- a/lib/graph.njae/vertex.rb +++ b/lib/graph.njae/vertex.rb @@ -1,5 +1,3 @@ -require 'ostruct' - # A simple graph library module GraphNjae @@ -14,8 +12,8 @@ module GraphNjae # Connect this vertex to another, creating an Edge to do so, and returning # the Edge - def connect(other) - e = Edge.new + def connect(other, edge_attributes = {}) + e = Edge.new edge_attributes e << self << other # self.edges << e # other.edges << e unless self === other @@ -39,5 +37,25 @@ module GraphNjae e.vertices.drop_while {|v| v != self}[1..-1]}.flatten end + def to_s + '' + end + + def to_dot(opts = {}) + if block_given? + yield self + else + dot = self.object_id.to_s + if opts.size > 0 + dot << ' {' + dot << opts.keys.map { |k| + (k.to_s + ' = "' + self.instance_eval(opts[k].to_s).to_s) + '"' + }.join(', ') + dot << '}' + end + dot << ';' + end + end + end end