Class: NoSE::QueryGraph::Edge

Inherits:
Object
  • Object
show all
Defined in:
lib/nose/query_graph.rb

Overview

An edge between two Nodes in a Graph

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(from, to, key) ⇒ Edge

Returns a new instance of Edge.



37
38
39
40
41
# File 'lib/nose/query_graph.rb', line 37

def initialize(from, to, key)
  @from = from
  @to = to
  @key = key
end

Instance Attribute Details

#fromObject (readonly)

Returns the value of attribute from.



35
36
37
# File 'lib/nose/query_graph.rb', line 35

def from
  @from
end

#keyObject (readonly)

Returns the value of attribute key.



35
36
37
# File 'lib/nose/query_graph.rb', line 35

def key
  @key
end

#toObject (readonly)

Returns the value of attribute to.



35
36
37
# File 'lib/nose/query_graph.rb', line 35

def to
  @to
end

Instance Method Details

#==(other) ⇒ Object Also known as: eql?

Edges are equal if the canonical parameters used to construct them are the same



51
52
53
54
# File 'lib/nose/query_graph.rb', line 51

def ==(other)
  return false unless other.is_a? Edge
  canonical_params == other.canonical_params
end

#canonical_paramsArray

Produce the parameters to initialize the canonical version of this edge (this accounts for different directionality of edges)

Returns:



64
65
66
67
68
69
70
# File 'lib/nose/query_graph.rb', line 64

def canonical_params
  if @from.entity.name > @to.entity.name
    [@from.entity.name, @to.entity.name, @key.name]
  else
    [@to.entity.name, @from.entity.name, @key.reverse.name]
  end
end

#hashObject



57
58
59
# File 'lib/nose/query_graph.rb', line 57

def hash
  canonical_params.hash
end

#inspectObject

:nocov:



44
45
46
# File 'lib/nose/query_graph.rb', line 44

def inspect
  @key.inspect
end