Class: Mementus::Edge
- Inherits:
-
Object
- Object
- Mementus::Edge
- Defined in:
- lib/mementus/edge.rb
Instance Attribute Summary collapse
-
#from ⇒ Object
readonly
Returns the value of attribute from.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#label ⇒ Object
readonly
Returns the value of attribute label.
-
#to ⇒ Object
readonly
Returns the value of attribute to.
Instance Method Summary collapse
- #==(edge) ⇒ Object (also: #eql?)
- #[](prop) ⇒ Object
- #hash ⇒ Object
-
#initialize(id: nil, from:, to:, label: :edge, props: {}) ⇒ Edge
constructor
A new instance of Edge.
- #nodes ⇒ Object
Constructor Details
#initialize(id: nil, from:, to:, label: :edge, props: {}) ⇒ Edge
Returns a new instance of Edge.
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/mementus/edge.rb', line 5 def initialize(id: nil, from:, to:, label: :edge, props: {}) @id = id @label = label @props = props.freeze @from = if from.is_a?(Integer) Node.new(id: from) else from end @to = if to.is_a?(Integer) Node.new(id: to) else to end end |
Instance Attribute Details
#from ⇒ Object (readonly)
Returns the value of attribute from.
3 4 5 |
# File 'lib/mementus/edge.rb', line 3 def from @from end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
3 4 5 |
# File 'lib/mementus/edge.rb', line 3 def id @id end |
#label ⇒ Object (readonly)
Returns the value of attribute label.
3 4 5 |
# File 'lib/mementus/edge.rb', line 3 def label @label end |
#to ⇒ Object (readonly)
Returns the value of attribute to.
3 4 5 |
# File 'lib/mementus/edge.rb', line 3 def to @to end |
Instance Method Details
#==(edge) ⇒ Object Also known as: eql?
31 32 33 |
# File 'lib/mementus/edge.rb', line 31 def ==(edge) from.id == edge.from.id && to.id == edge.to.id && label == edge.label end |
#[](prop) ⇒ Object
23 24 25 |
# File 'lib/mementus/edge.rb', line 23 def [](prop) @props[prop] end |
#hash ⇒ Object
37 38 39 |
# File 'lib/mementus/edge.rb', line 37 def hash [from.id, to.id].hash end |
#nodes ⇒ Object
27 28 29 |
# File 'lib/mementus/edge.rb', line 27 def nodes [@from, @to] end |