class TablePrint::Row
def collapse!
def collapse! children.each(&:collapse!) # depth-first. start collapsing from the bottom and work our way up. to_absorb = [] children.each do |group| next unless can_absorb?(group) to_absorb << group end to_absorb.each do |absorbable_group| absorbable_row = absorbable_group.children.shift # missing associations create groups with no rows children.delete(absorbable_group) and next unless absorbable_row @cells.merge!(absorbable_row.cells) i = children.index(absorbable_group) children.delete(absorbable_group) if absorbable_group.children.empty? insert_children(i, absorbable_row.children) if absorbable_row.children.any? end end