X-Git-Url: https://git.njae.me.uk/?a=blobdiff_plain;f=lib%2Fgraph.njae%2Fvertex.rb;h=4ac903c2bea7f9424ab34ecb9c6a8b42a57cab88;hb=99e4223d9b3baef392d4a6b0b996078f06fcadf7;hp=6b34351740c04c0754a5e431f1ea38bd7773a0a0;hpb=353a5d54ad4014af126c76617d9b02029a3ee98c;p=graph.njae.git diff --git a/lib/graph.njae/vertex.rb b/lib/graph.njae/vertex.rb index 6b34351..4ac903c 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,11 +12,11 @@ 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 + # self.edges << e + # other.edges << e unless self === other e end @@ -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