Class: Pacer::Neo4j2::Algo::BlockPathExpander

Inherits:
Object
  • Object
show all
Includes:
PathExpander
Defined in:
lib/pacer-neo4j2/algo/block_path_expander.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(block, rev, graph, max_depth) ⇒ BlockPathExpander

Returns a new instance of BlockPathExpander.



11
12
13
14
15
16
# File 'lib/pacer-neo4j2/algo/block_path_expander.rb', line 11

def initialize(block, rev, graph, max_depth)
  @block = block
  @rev = rev
  @graph = graph
  @max_depth = max_depth
end

Instance Attribute Details

#blockObject (readonly)

Returns the value of attribute block.



9
10
11
# File 'lib/pacer-neo4j2/algo/block_path_expander.rb', line 9

def block
  @block
end

#graphObject (readonly)

Returns the value of attribute graph.



9
10
11
# File 'lib/pacer-neo4j2/algo/block_path_expander.rb', line 9

def graph
  @graph
end

#max_depthObject (readonly)

Returns the value of attribute max_depth.



9
10
11
# File 'lib/pacer-neo4j2/algo/block_path_expander.rb', line 9

def max_depth
  @max_depth
end

#revObject (readonly)

Returns the value of attribute rev.



9
10
11
# File 'lib/pacer-neo4j2/algo/block_path_expander.rb', line 9

def rev
  @rev
end

Instance Method Details

#expand(path, state) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
# File 'lib/pacer-neo4j2/algo/block_path_expander.rb', line 18

def expand(path, state)
  path = PathWrapper.new(path, graph)
  if max_depth and path.length >= max_depth
    result = []
  else
    result = block.call path, state
  end
  pipe = Pacer::Pipes::NakedPipe.new
  pipe.set_starts result_to_enumerable(result)
  pipe
end

#result_to_enumerable(result) ⇒ Object



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/pacer-neo4j2/algo/block_path_expander.rb', line 34

def result_to_enumerable(result)
  case result
  when PathWrapper
    fail "Don't just return the arguments in your expander, return edges!"
  when Pacer::Route
    if result.element_type == :edge
      result.pipe.starts
    else
      fail "Expander must return edges"
    end
  when Pacer::Wrappers::EdgeWrapper
    Pacer::Pipes::EnumerablePipe.new [result]
  when Pacer::Pipes::WrappingPipe
    result.starts
  when Pipe
    result
  when Enumerable
    Pacer::Pipes::EnumerablePipe.new result
  when nil
    Pacer::Pipes::EnumerablePipe.new []
  else
    fail "Can't figure out what to do with #{ result.class }"
  end
end

#reverseObject



30
31
32
# File 'lib/pacer-neo4j2/algo/block_path_expander.rb', line 30

def reverse
  BlockPathExpander.new rev, block, graph, max_depth
end