Sha256: 62475c5f695348d2207bb59bb19aa1652d995f41f2c14e666babf04899f7d62d

Contents?: true

Size: 1.07 KB

Versions: 39

Compression:

Stored size: 1.07 KB

Contents

require "pact_broker/domain/group"

=begin
  Splits all index_items up into groups of non-connecting index_items.
=end

module PactBroker

  module Relationships

    class Groupify

      def self.call index_items
        recurse_groups([], index_items.dup).collect { |group| Domain::Group.new(group) }
      end

      def self.recurse_groups groups, index_item_pool
        if index_item_pool.empty?
          groups
        else
          first, *rest = index_item_pool
          group = [first]
          new_connections = true
          while new_connections
            new_connections = false
            group = rest.inject(group) do |connected, candidate|
              if connected.select { |index_item| index_item.connected?(candidate) }.any?
                new_connections = true
                connected + [candidate]
              else
                connected
              end
            end

            rest = rest - group
            group.uniq
          end

          recurse_groups(groups + [group], index_item_pool - group)
        end
      end
    end

  end
end

Version data entries

39 entries across 39 versions & 1 rubygems

Version Path
pact_broker-2.107.1 lib/pact_broker/relationships/groupify.rb
pact_broker-2.107.0 lib/pact_broker/relationships/groupify.rb
pact_broker-2.107.0.beta.1 lib/pact_broker/relationships/groupify.rb
pact_broker-2.106.0 lib/pact_broker/relationships/groupify.rb
pact_broker-2.105.0 lib/pact_broker/relationships/groupify.rb
pact_broker-2.104.0 lib/pact_broker/relationships/groupify.rb
pact_broker-2.103.0 lib/pact_broker/relationships/groupify.rb
pact_broker-2.102.2 lib/pact_broker/relationships/groupify.rb
pact_broker-2.102.1 lib/pact_broker/relationships/groupify.rb
pact_broker-2.102.0 lib/pact_broker/relationships/groupify.rb
pact_broker-2.101.0 lib/pact_broker/relationships/groupify.rb
pact_broker-2.100.0 lib/pact_broker/relationships/groupify.rb
pact_broker-2.99.0 lib/pact_broker/relationships/groupify.rb
pact_broker-2.98.0 lib/pact_broker/relationships/groupify.rb
pact_broker-2.97.0 lib/pact_broker/relationships/groupify.rb
pact_broker-2.96.0 lib/pact_broker/relationships/groupify.rb
pact_broker-2.95.1 lib/pact_broker/relationships/groupify.rb
pact_broker-2.95.0 lib/pact_broker/relationships/groupify.rb
pact_broker-2.94.0 lib/pact_broker/relationships/groupify.rb
pact_broker-2.93.4 lib/pact_broker/relationships/groupify.rb