Sha256: a707516a3d37c6d9d3b826889e53b04b0f0fcf93ce5c9b2861e109377aa43c0d

Contents?: true

Size: 833 Bytes

Versions: 31

Compression:

Stored size: 833 Bytes

Contents

# frozen_string_literal: true

require 'eac_ruby_utils/core_ext'

module EhbrsRubyUtils
  class CircularListSpreader
    require_sub __FILE__
    common_constructor :items

    # @return [EhbrsRubyUtils::SpreaderT1::GroupLevel]
    def build_root
      r = ::EhbrsRubyUtils::CircularListSpreader::GroupLevel.new('ROOT')
      items.each { |item| r.push(item.to_circular_list_spreader_path, item) }
      r
    end

    # @return [Array]
    def result
      base_list = ::EhbrsRubyUtils::CircularListSpreader::List.empty
      build_root.pop_all.each do |item|
        base_list = lists_with_item(base_list, item).max
      end
      base_list.items.map(&:item)
    end

    def lists_with_item(base_list, item)
      (base_list.count + 1).times.map do |position|
        base_list.insert(position, item)
      end
    end
  end
end

Version data entries

31 entries across 31 versions & 1 rubygems

Version Path
ehbrs_ruby_utils-0.44.2 lib/ehbrs_ruby_utils/circular_list_spreader.rb
ehbrs_ruby_utils-0.44.1 lib/ehbrs_ruby_utils/circular_list_spreader.rb
ehbrs_ruby_utils-0.44.0 lib/ehbrs_ruby_utils/circular_list_spreader.rb
ehbrs_ruby_utils-0.41.1 lib/ehbrs_ruby_utils/circular_list_spreader.rb
ehbrs_ruby_utils-0.41.0 lib/ehbrs_ruby_utils/circular_list_spreader.rb
ehbrs_ruby_utils-0.40.0 lib/ehbrs_ruby_utils/circular_list_spreader.rb
ehbrs_ruby_utils-0.39.0 lib/ehbrs_ruby_utils/circular_list_spreader.rb
ehbrs_ruby_utils-0.38.0 lib/ehbrs_ruby_utils/circular_list_spreader.rb
ehbrs_ruby_utils-0.37.0 lib/ehbrs_ruby_utils/circular_list_spreader.rb
ehbrs_ruby_utils-0.36.1 lib/ehbrs_ruby_utils/circular_list_spreader.rb
ehbrs_ruby_utils-0.36.0 lib/ehbrs_ruby_utils/circular_list_spreader.rb
ehbrs_ruby_utils-0.35.0 lib/ehbrs_ruby_utils/circular_list_spreader.rb
ehbrs_ruby_utils-0.33.0 lib/ehbrs_ruby_utils/circular_list_spreader.rb
ehbrs_ruby_utils-0.32.0 lib/ehbrs_ruby_utils/circular_list_spreader.rb
ehbrs_ruby_utils-0.31.0 lib/ehbrs_ruby_utils/circular_list_spreader.rb
ehbrs_ruby_utils-0.30.0 lib/ehbrs_ruby_utils/circular_list_spreader.rb
ehbrs_ruby_utils-0.29.0 lib/ehbrs_ruby_utils/circular_list_spreader.rb
ehbrs_ruby_utils-0.28.0 lib/ehbrs_ruby_utils/circular_list_spreader.rb
ehbrs_ruby_utils-0.27.1 lib/ehbrs_ruby_utils/circular_list_spreader.rb
ehbrs_ruby_utils-0.27.0 lib/ehbrs_ruby_utils/circular_list_spreader.rb