Class: Link
- Inherits:
-
Hash
- Object
- Hash
- Link
- Defined in:
- lib/rgraph/link.rb
Instance Method Summary collapse
-
#initialize(attributes) ⇒ Link
constructor
A new instance of Link.
- #source ⇒ Object
- #target ⇒ Object
- #type ⇒ Object
Constructor Details
#initialize(attributes) ⇒ Link
Returns a new instance of Link.
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
# 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 |
Instance Method Details
#source ⇒ Object
19 20 21 |
# File 'lib/rgraph/link.rb', line 19 def source self[:source] end |
#target ⇒ Object
23 24 25 |
# File 'lib/rgraph/link.rb', line 23 def target self[:target] end |
#type ⇒ Object
27 28 29 |
# File 'lib/rgraph/link.rb', line 27 def type self[:type] end |