Class: Mementus::Edge

Inherits:
Object
  • Object
show all
Defined in:
lib/mementus/edge.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#fromObject (readonly)

Returns the value of attribute from.



3
4
5
# File 'lib/mementus/edge.rb', line 3

def from
  @from
end

#idObject (readonly)

Returns the value of attribute id.



3
4
5
# File 'lib/mementus/edge.rb', line 3

def id
  @id
end

#labelObject (readonly)

Returns the value of attribute label.



3
4
5
# File 'lib/mementus/edge.rb', line 3

def label
  @label
end

#toObject (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

#hashObject



37
38
39
# File 'lib/mementus/edge.rb', line 37

def hash
  [from.id, to.id].hash
end

#nodesObject



27
28
29
# File 'lib/mementus/edge.rb', line 27

def nodes
  [@from, @to]
end