lib/visualize_ruby/edge.rb in visualize_ruby-0.8.0 vs lib/visualize_ruby/edge.rb in visualize_ruby-0.11.0

- old
+ new

@@ -1,23 +1,35 @@ module VisualizeRuby class Edge - attr_reader :name, - :node_a, - :node_b, + include Touchable + include Optionalable + attr_reader :nodes, :dir, - :style, - :color + :style - def initialize(name: nil, nodes:, dir: :forward, style: :solid, color: nil) - @name = name.to_s if name - @node_a = nodes[0] - @node_b = nodes[1] - @dir = dir - @style = style - @color = color + attr_accessor :color, + :display + + def initialize(name: nil, nodes:, dir: :forward, type: :default, display: :visual, **opts) + @name = name.to_s if name + @nodes = nodes + @dir = dir + @style = style + @color = color + @type = type + @display = display + post_initialize(opts) end + def node_a + nodes[0] + end + + def node_b + nodes[1] + end + def to_a [ node_a.name.to_s, name, direction_symbol, @@ -34,9 +46,19 @@ end end def inspect "#<VisualizeRuby::Edge #{to_a.join(" ")}>" + end + + def ==(other) + other.class == self.class && other.hash == self.hash + end + + alias_method :eql?, :== + + def hash + [dir, name, nodes.map(&:hash), style, color].hash end alias_method :to_s, :inspect end end