Class: Link
- Inherits:
-
Object
- Object
- Link
- Defined in:
- lib/rgraph/link.rb
Instance Attribute Summary collapse
-
#source ⇒ Object
Returns the value of attribute source.
-
#target ⇒ Object
Returns the value of attribute target.
-
#type ⇒ Object
Returns the value of attribute type.
Instance Method Summary collapse
- #[](attribute) ⇒ Object
-
#initialize(attributes) ⇒ Link
constructor
A new instance of Link.
Constructor Details
#initialize(attributes) ⇒ Link
Returns a new instance of Link.
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(attributes) @attributes = attributes @source = @attributes.delete(:source) @target = @attributes.delete(:target) @type = @attributes.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 @attributes[:weight] ||= 1 @source.neighbours << @target @target.neighbours << @source unless @type == 'directed' end |
Instance Attribute Details
#source ⇒ Object
Returns the value of attribute source.
2 3 4 |
# File 'lib/rgraph/link.rb', line 2 def source @source end |
#target ⇒ Object
Returns the value of attribute target.
2 3 4 |
# File 'lib/rgraph/link.rb', line 2 def target @target end |
#type ⇒ Object
Returns the value of attribute type.
2 3 4 |
# File 'lib/rgraph/link.rb', line 2 def type @type end |
Instance Method Details
#[](attribute) ⇒ Object
21 22 23 |
# File 'lib/rgraph/link.rb', line 21 def [](attribute) @attributes[attribute] end |