Sha256: dd4b8741786fea7e8cd584301b0cd5520df4f6d0c8de63f7fb6114cd09db49dd
Contents?: true
Size: 1.38 KB
Versions: 6
Compression:
Stored size: 1.38 KB
Contents
# frozen_string_literal: true require 'eac_ruby_utils/core_ext' require 'ehbrs_ruby_utils/spreader_t1/base_level' require 'ehbrs_ruby_utils/spreader_t1/item_level' module EhbrsRubyUtils class SpreaderT1 class GroupLevel include ::EhbrsRubyUtils::SpreaderT1::BaseLevel enable_simple_cache common_constructor :label def push(path, item) child_path = path.dup current = child_path.shift if child_path.any? push_group_level(current, child_path, item) else push_item_level(current, item) end end def pop children.values.max.pop end def pop_all r = [] while remaining?; r << pop; end r end def remaining_i children.values.inject(0) { |a, e| a + e.remaining_i } end def total_i children.values.inject(0) { |a, e| a + e.total_i } end private attr_accessor :item def push_group_level(current, child_path, item) children[current] ||= self.class.new(current) children[current].push(child_path, item) end def children @children ||= {} end def push_item_level(current, item) raise "Key \"#{current}\" already used" if children[current].present? children[current] = ::EhbrsRubyUtils::SpreaderT1::ItemLevel.new(item) end end end end
Version data entries
6 entries across 6 versions & 1 rubygems