lib/rgraph/link.rb in rgraph-0.0.15 vs lib/rgraph/link.rb in rgraph-0.1.1

- old
+ new

@@ -1,25 +1,24 @@ class Link attr_accessor :source, :target, :type - def initialize(arg) - @args = arg - @source = @args.delete(:source) - @target = @args.delete(:target) - @type = @args.delete(:type) || 'undirected' + def initialize(attributes) + @attributes = attributes + @source = @attributes.delete(:source) + @target = @attributes.delete(:target) + @type = @attributes.delete(:type) || 'undirected' raise Exception.new("source cant be nil") unless @source raise Exception.new("target cant be nil") unless @target raise Exception.new("source must be of type Node") unless @source.is_a? Node raise Exception.new("target must be of type Node") unless @target.is_a? Node - @args[:weight] ||= 1 + @attributes[:weight] ||= 1 @source.neighbours << @target @target.neighbours << @source unless @type == 'directed' end - def method_missing(name, *args) - super unless args.empty? - @args[name] + def [](attribute) + @attributes[attribute] end end