Sha256: 2b73e45a11efc7b06c0533a317744da3224cef098b961881e7a54e9c563354a3

Contents?: true

Size: 1.41 KB

Versions: 9

Compression:

Stored size: 1.41 KB

Contents

require 'tangle/mixin/connectedness'

module Tangle
  module Mixin
    #
    # Mixin for adding ancestry features
    #
    module Ancestry
      #
      # Mixins for adding ancestry relations to a digraph
      #
      module Graph
        include Tangle::Mixin::Connectedness::Graph

        def ancestor_subgraph(vertex)
          subgraph { |other| vertex.ancestor?(other) }
        end

        def descendant_subgraph(vertex)
          subgraph { |other| vertex.descendant?(other) }
        end
      end

      #
      # Mixins for adding ancestry relations to vertices in a digraph
      #
      module Vertex
        include Tangle::Mixin::Connectedness::Vertex

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

        def parents
          neighbours(parent_edges)
        end

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

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

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

        def children
          neighbours(child_edges)
        end

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

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

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
tangle-0.6.4 lib/tangle/mixin/ancestry.rb
tangle-0.6.3 lib/tangle/mixin/ancestry.rb
tangle-0.6.2 lib/tangle/mixin/ancestry.rb
tangle-0.6.1 lib/tangle/mixin/ancestry.rb
tangle-0.6.0 lib/tangle/mixin/ancestry.rb
tangle-0.5.1 lib/tangle/mixin/ancestry.rb
tangle-0.5.0 lib/tangle/mixin/ancestry.rb
tangle-0.4.2 lib/tangle/mixin/ancestry.rb
tangle-0.4.0 lib/tangle/mixin/ancestry.rb