Module: Pacer::Core::Graph::PathRoute

Defined in:
lib/pacer/transform/path_tree.rb,
lib/pacer/core/graph/path_route.rb,
lib/pacer/transform/wrapped_path.rb

Instance Method Summary collapse

Instance Method Details

#hashifyObject



86
87
88
89
90
91
92
93
94
95
96
# File 'lib/pacer/core/graph/path_route.rb', line 86

def hashify
  map(element_type: :hash, route_name: 'trees') do |path|
    path.to_a.reverse.reduce({}) do |tree, element|
      if element.element_type == :vertex
        tree.merge element.properties
      else
        { element.label => [tree] }
      end
    end
  end
end

#heads(et = :vertex) ⇒ Object



78
79
80
# File 'lib/pacer/core/graph/path_route.rb', line 78

def heads(et = :vertex)
  super et
end

#help(section = nil) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/pacer/core/graph/path_route.rb', line 3

def help(section = nil)
  case section
  when :paths
    puts <<HELP
The following path-specific route methods are available:

See also the :arrays section for more available methods

#subgraph(target_graph, opts)   Add each element in the path to the graph
target_graph: PacerGraph (optional) if not specified creates a new TG.
opts:
  create_vertices: Boolean          Create vertices for edges if needed
      Edges can not be created without both vertices being present. If
      this option is not set and a vertex is missing, raises a
      Pacer::ElementNotFound exception.
  ignore_missing_vertices: Boolean  Squelches the above mentioned exception
  show_missing_vertices: Boolean    Complain about missing vertices

#hashify            Make a hash of the properties and relationships of the path
This is just a simple view on the data to facilitate analysis

HELP
  else
    super
  end
  description
end

#payloadsObject



56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/pacer/core/graph/path_route.rb', line 56

def payloads
  map element_type: :path, route_name: 'payloads' do |path|
    path.flat_map do |e|
      e = e.element if e.is_a? Pacer::Wrappers::ElementWrapper
      r = []
      while e.is_a? Pacer::Payload::Element
        r.unshift e.payload
        e = e.element
      end
      if r == []
        [nil]
      else
        r
      end
    end
  end
end

#subgraph(target_graph = nil, opts = {}) ⇒ Object



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/pacer/core/graph/path_route.rb', line 31

def subgraph(target_graph = nil, opts = {})
  raise "Can't create a subgraph within itself." if target_graph == graph
  target_graph ||= Pacer.tg
  target_graph.vertex_name ||= graph.vertex_name
  missing_edges = Set[]
  bulk_job(nil, target_graph) do |path|
    path.select { |e| e.is_a? Pacer::Vertex }.each do |vertex|
      vertex.clone_into target_graph
    end
    path.select { |e| e.is_a? Pacer::Edge }.each do |edge|
      unless edge.clone_into target_graph, ignore_missing_vertices: true
        missing_edges << edge
      end
    end
  end
  if missing_edges.any?
    missing_edges.to_route(graph: graph, element_type: :edge).bulk_job nil, target_graph do |edge|
      edge.clone_into target_graph,
        ignore_missing_vertices: opts[:ignore_missing_vertices],
        show_missing_vertices: opts[:show_missing_vertices]
    end
  end
  target_graph
end

#tails(et = :vertex) ⇒ Object



82
83
84
# File 'lib/pacer/core/graph/path_route.rb', line 82

def tails(et = :vertex)
  super et
end

#transposeObject



74
75
76
# File 'lib/pacer/core/graph/path_route.rb', line 74

def transpose
  map(element_type: :array, &:to_a).transpose
end

#tree(&block) ⇒ Object

The default comparator block is { |prev, current| prev == current }



17
18
19
# File 'lib/pacer/transform/path_tree.rb', line 17

def tree(&block)
  wrapped.chain_route transform: :path_tree, element_type: :array, compare: block
end

#wrapped(*exts) ⇒ Object



5
6
7
# File 'lib/pacer/transform/wrapped_path.rb', line 5

def wrapped(*exts)
  chain_route transform: :wrap_path, element_type: :path
end