lib/graph/edge.rb in graph-rb-0.1.0 vs lib/graph/edge.rb in graph-rb-0.1.1
- old
+ new
@@ -1,11 +1,17 @@
class Graph::Edge
- attr_reader :ukey, :graph, :from, :to
+ attr_reader :key, :graph, :from, :to
+ attr_accessor :weight
- def initialize(from, to)
+ def initialize(from, to, weight: 1)
@from = from
@to = to
- @ukey = "from_#{from.uid}_to_#{to.uid}"
+ @key = "from_#{from.key}_to_#{to.key}"
+ @weight = weight
+ end
+
+ def to_h
+ { from: from.key, to: to.key, weight: weight }
end
private
def add_to(graph)