class Link

Public Class Methods

new(attributes) click to toggle source
# File lib/rgraph/link.rb, line 2
def initialize(attributes)
  self[:type] = 'undirected'
  self[:weight] = 1

  attributes.each_pair do |key, value|
    self[key] = value
  end

  raise Exception.new("source cant be nil") unless self[:source]
  raise Exception.new("target cant be nil") unless self[:target]
  raise Exception.new("source must be of type Node") unless self[:source].is_a? Node
  raise Exception.new("target must be of type Node") unless self[:target].is_a? Node

  self[:source].neighbours << self[:target]
  self[:target].neighbours << self[:source] unless self[:type] == 'directed'
end

Public Instance Methods

source() click to toggle source
# File lib/rgraph/link.rb, line 19
def source
  self[:source]
end
target() click to toggle source
# File lib/rgraph/link.rb, line 23
def target
  self[:target]
end
type() click to toggle source
# File lib/rgraph/link.rb, line 27
def type
  self[:type]
end