Class: EhbrsRubyUtils::CircularListSpreader

Inherits:
Object
  • Object
show all
Defined in:
lib/ehbrs_ruby_utils/circular_list_spreader.rb,
lib/ehbrs_ruby_utils/circular_list_spreader/list.rb,
lib/ehbrs_ruby_utils/circular_list_spreader/base_level.rb,
lib/ehbrs_ruby_utils/circular_list_spreader/item_level.rb,
lib/ehbrs_ruby_utils/circular_list_spreader/group_level.rb,
lib/ehbrs_ruby_utils/circular_list_spreader/list/item_pair_spreadness.rb

Defined Under Namespace

Modules: BaseLevel Classes: GroupLevel, ItemLevel, List

Instance Method Summary collapse

Instance Method Details

#build_rootEhbrsRubyUtils::SpreaderT1::GroupLevel

Returns:

  • (EhbrsRubyUtils::SpreaderT1::GroupLevel)


11
12
13
14
15
# File 'lib/ehbrs_ruby_utils/circular_list_spreader.rb', line 11

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

#lists_with_item(base_list, item) ⇒ Object



26
27
28
29
30
# File 'lib/ehbrs_ruby_utils/circular_list_spreader.rb', line 26

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

#resultArray

Returns:

  • (Array)


18
19
20
21
22
23
24
# File 'lib/ehbrs_ruby_utils/circular_list_spreader.rb', line 18

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