Module: Tangle::Mixin::Ancestry::Vertex

Includes:
Connectedness::Vertex
Defined in:
lib/tangle/mixin/ancestry.rb

Overview

Mixins for adding ancestry relations to vertices in a digraph

Instance Method Summary collapse

Methods included from Connectedness::Vertex

#connected?

Instance Method Details

#ancestor?(other) ⇒ Boolean

Returns:

  • (Boolean)


42
43
44
# File 'lib/tangle/mixin/ancestry.rb', line 42

def ancestor?(other)
  connected?(other, test_method: :parent?)
end

#child?(other) ⇒ Boolean

Returns:

  • (Boolean)


54
55
56
# File 'lib/tangle/mixin/ancestry.rb', line 54

def child?(other)
  @graph.edges.any? { |edge| edge.parent?(self) && edge.child?(other) }
end

#child_edgesObject



46
47
48
# File 'lib/tangle/mixin/ancestry.rb', line 46

def child_edges
  @graph.edges { |edge| edge.parent?(self) }
end

#childrenObject



50
51
52
# File 'lib/tangle/mixin/ancestry.rb', line 50

def children
  neighbours(child_edges)
end

#descendant?(other) ⇒ Boolean

Returns:

  • (Boolean)


58
59
60
# File 'lib/tangle/mixin/ancestry.rb', line 58

def descendant?(other)
  connected?(other, test_method: :child?)
end

#parent?(other) ⇒ Boolean

Returns:

  • (Boolean)


38
39
40
# File 'lib/tangle/mixin/ancestry.rb', line 38

def parent?(other)
  @graph.edges.any? { |edge| edge.child?(self) && edge.parent?(other) }
end

#parent_edgesObject



30
31
32
# File 'lib/tangle/mixin/ancestry.rb', line 30

def parent_edges
  @graph.edges { |edge| edge.child?(self) }
end

#parentsObject



34
35
36
# File 'lib/tangle/mixin/ancestry.rb', line 34

def parents
  neighbours(parent_edges)
end