Class: Pacer::Neo4j::Algo::PathPipe

Inherits:
Pipes::RubyPipe
  • Object
show all
Defined in:
lib/pacer-neo4j/algo/path_pipe.rb

Direct Known Subclasses

PathFromPathPipe

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(algo, graph, target, max_hits) ⇒ PathPipe

Returns a new instance of PathPipe.



13
14
15
16
17
18
19
# File 'lib/pacer-neo4j/algo/path_pipe.rb', line 13

def initialize(algo, graph, target, max_hits)
  super()
  @algo = algo
  @max_hits = max_hits || -1
  @graph = graph.blueprints_graph
  @target = unwrap target if target
end

Instance Attribute Details

#algoObject (readonly)

Returns the value of attribute algo.



10
11
12
# File 'lib/pacer-neo4j/algo/path_pipe.rb', line 10

def algo
  @algo
end

#current_pathsObject

Returns the value of attribute current_paths.



11
12
13
# File 'lib/pacer-neo4j/algo/path_pipe.rb', line 11

def current_paths
  @current_paths
end

#graphObject (readonly)

Returns the value of attribute graph.



10
11
12
# File 'lib/pacer-neo4j/algo/path_pipe.rb', line 10

def graph
  @graph
end

#hitsObject

Returns the value of attribute hits.



11
12
13
# File 'lib/pacer-neo4j/algo/path_pipe.rb', line 11

def hits
  @hits
end

#max_hitsObject (readonly)

Returns the value of attribute max_hits.



10
11
12
# File 'lib/pacer-neo4j/algo/path_pipe.rb', line 10

def max_hits
  @max_hits
end

#targetObject (readonly)

Returns the value of attribute target.



10
11
12
# File 'lib/pacer-neo4j/algo/path_pipe.rb', line 10

def target
  @target
end

Instance Method Details

#next_rawObject



51
52
53
# File 'lib/pacer-neo4j/algo/path_pipe.rb', line 51

def next_raw
  unwrap starts.next
end

#next_raw_pathObject



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/pacer-neo4j/algo/path_pipe.rb', line 33

def next_raw_path
  loop do
    if current_paths
      if hits == 0
        self.current_paths = nil
      elsif current_paths.hasNext
        self.hits -= 1
        return current_paths.next
      else
        self.current_paths = nil
      end
    else
      self.hits = max_hits
      self.current_paths = @algo.findAllPaths(next_raw, target).iterator
    end
  end
end

#processNextStartObject



21
22
23
24
25
26
27
28
29
30
31
# File 'lib/pacer-neo4j/algo/path_pipe.rb', line 21

def processNextStart
  next_raw_path.map do |e|
    if e.is_a? Node
      Neo4jVertex.new e, graph
    elsif e.is_a? Relationship
      Neo4jEdge.new e, graph
    else
      e
    end
  end
end

#unwrap(vertex) ⇒ Object



55
56
57
58
59
60
61
# File 'lib/pacer-neo4j/algo/path_pipe.rb', line 55

def unwrap(vertex)
  if vertex.respond_to? :element
    vertex.element.raw_element
  else
    vertex.raw_element
  end
end