class Graphsrb::Edge

Attributes

initial_vertex[R]
terminal_vertex[R]
vertex1[R]
vertex2[R]
weight[R]

Public Class Methods

new(id1, id2, args={}) click to toggle source
# File lib/graphsrb/edge.rb, line 4
def initialize(id1, id2, args={})
  if id1 == id2
    raise Graphsrb::EdgeInitializationError, "Vertex id's must be different from each other"
  end

  @vertex1 = Graphsrb::Vertex.new(id1)
  @vertex2 = Graphsrb::Vertex.new(id2)
  @weight = args.fetch(:weight, 1)
end

Public Instance Methods

==(other) click to toggle source
# File lib/graphsrb/edge.rb, line 17
def ==(other)
  (vertex1.id == other.vertex1.id) && (vertex2.id == other.vertex2.id) ||
  (vertex1.id == other.vertex2.id) && (vertex2.id == other.vertex1.id)
end
eql?(other) click to toggle source
# File lib/graphsrb/edge.rb, line 22
def eql?(other)
  self == other
end
to_json() click to toggle source
# File lib/graphsrb/edge.rb, line 30
def to_json
  {vertex1: vertex1.id, vertex2: vertex2.id, weight: weight}.to_json
end
to_s() click to toggle source
# File lib/graphsrb/edge.rb, line 26
def to_s
  "(#{vertex1.id}, #{vertex2.id}, weight:#{weight})"
end