Class: Link

Inherits:
Object
  • Object
show all
Defined in:
lib/rgraph/link.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(arg) ⇒ Link

Returns a new instance of Link.

Raises:

  • (Exception)


4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/rgraph/link.rb', line 4

def initialize(arg)
  @args = arg
  @source = @args.delete(:source)
  @target = @args.delete(:target)
  @type = @args.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

  @source.neighbours << @target
  @target.neighbours << @source unless @type == 'directed'
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name, *args) ⇒ Object



21
22
23
24
# File 'lib/rgraph/link.rb', line 21

def method_missing(name, *args)
  super unless args.empty?
  @args[name]
end

Instance Attribute Details

#sourceObject

Returns the value of attribute source.



2
3
4
# File 'lib/rgraph/link.rb', line 2

def source
  @source
end

#targetObject

Returns the value of attribute target.



2
3
4
# File 'lib/rgraph/link.rb', line 2

def target
  @target
end

#typeObject

Returns the value of attribute type.



2
3
4
# File 'lib/rgraph/link.rb', line 2

def type
  @type
end