Class: Neography::PathTraverser

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/neography/path_traverser.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(from, to, algorithm, all = false, types = nil, dir = "all") ⇒ PathTraverser

Returns a new instance of PathTraverser.



7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/neography/path_traverser.rb', line 7

def initialize(from, to, algorithm, all=false, types = nil, dir = "all" )
  @from  = from
  @to = to
  @algorithm = algorithm
  @all = all
  @relationships = Array.new
  types.each do |type|
    @relationships << {"type" => type.to_s, "direction" => dir.to_s }
  end unless types.nil?
  @get = ["node","rel"]
  @loaded_nodes = Array.new
  @loaded_rels = Array.new
end

Instance Attribute Details

#algorithmObject

Returns the value of attribute algorithm.



5
6
7
# File 'lib/neography/path_traverser.rb', line 5

def algorithm
  @algorithm
end

#depth(d) ⇒ Object

Returns the value of attribute depth.



5
6
7
# File 'lib/neography/path_traverser.rb', line 5

def depth
  @depth
end

#getObject

Returns the value of attribute get.



5
6
7
# File 'lib/neography/path_traverser.rb', line 5

def get
  @get
end

#relationshipsObject Also known as: rels

Returns the value of attribute relationships.



5
6
7
# File 'lib/neography/path_traverser.rb', line 5

def relationships
  @relationships
end

Instance Method Details

#both(type) ⇒ Object



33
34
35
36
# File 'lib/neography/path_traverser.rb', line 33

def both(type)
  @relationships << {"type" => type.to_s, "direction" => "all"}
  self
end

#eachObject



60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# File 'lib/neography/path_traverser.rb', line 60

def each
  iterator.each do |path|
    paths = Array.new

    if @get.include?("node")
      path["nodes"].each_with_index do |n, i|
        @loaded_nodes[get_id(n)] = Neography::Node.load(n) if @loaded_nodes.at(get_id(n)).nil?
        paths[i * 2] =  @loaded_nodes[get_id(n)]
      end
    end

    if @get.include?("rel") 
      path["relationships"].each_with_index do |r, i|
        @loaded_rels[get_id(r)] = Neography::Relationship.load(r)  if @loaded_rels.at(get_id(r)).nil?
        paths[i * 2 + 1] =  @loaded_rels[get_id(r)]
      end
    end
 
    yield paths.compact
  end
end

#empty?Boolean

Returns:

  • (Boolean)


82
83
84
# File 'lib/neography/path_traverser.rb', line 82

def empty?
  first == nil
end

#incoming(type) ⇒ Object



43
44
45
46
# File 'lib/neography/path_traverser.rb', line 43

def incoming(type)
  @relationships << {"type" => type.to_s, "direction" => "in"}
  self
end

#iteratorObject



86
87
88
89
90
91
92
# File 'lib/neography/path_traverser.rb', line 86

def iterator
  if @all.nil?
    @from.neo_server.get_path(@from, @to, @relationships, @depth, @algorithm)
  else
    @from.neo_server.get_paths(@from, @to, @relationships, @depth, @algorithm)
  end
end

#nodesObject



21
22
23
24
# File 'lib/neography/path_traverser.rb', line 21

def nodes
  @get = ["node"]
  self
end

#outgoing(type) ⇒ Object



38
39
40
41
# File 'lib/neography/path_traverser.rb', line 38

def outgoing(type)
  @relationships << {"type" => type.to_s, "direction" => "out"}
  self
end

#sizeObject Also known as: length



54
55
56
# File 'lib/neography/path_traverser.rb', line 54

def size
  [*self].size
end