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
# 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 = 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



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

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

#eachObject



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

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

    if @get.include?("node")
      path["nodes"].each_with_index do |n, i|
        @loaded[n.split('/').last.to_i] = Neography::Node.load(n) if @loaded.at(n.split('/').last.to_i).nil?
        paths[i * 2] =  @loaded[n.split('/').last.to_i]
      end
    end

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

#empty?Boolean

Returns:

  • (Boolean)


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

def empty?
  first == nil
end

#incoming(type) ⇒ Object



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

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

#iteratorObject



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

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



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

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

#outgoing(type) ⇒ Object



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

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

#sizeObject Also known as: length



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

def size
  [*self].size
end