<commit_before>module ObjectTable::Printable

  def _get_printable_column(name, column)
    padding = [nil] * (column.rank - 1)
    rows = column.shape[-1].times.map do |i|
      row = column[*padding, i]
      str = row.is_a?(NArray) ? row.inspect.partition("\n")[-1].strip : row.inspect
      str.split("\n")
    end

    name = name.to_s
    [[name]] + rows + [[name]]
  end

  def _get_printable_line_numbers(numbers)
    rows = numbers.map do |i|
      ["#{i}: "]
    end

    [['']] + rows + [['']]
  end

  def inspect(max_section = 5, col_padding = 2)
    header = "#{self.class}(#{nrows}, #{ncols})\n"
    printed_columns = []

    if nrows > max_section * 2
      head = (0...max_section)
      tail = ((nrows - max_section)...nrows)

      printed_columns.push _get_printable_line_numbers(head.to_a + tail.to_a)

      printed_columns += columns.map do |name, c|
        padding = [nil] * (c.rank - 1)
        c = c.slice(*padding, [head, tail])
        _get_printable_column(name, c)
      end
    else
      max_section = -1
      printed_columns.push _get_printable_line_numbers(0...nrows)
      printed_columns += columns.map do |name, c|
        _get_printable_column(name, c)
      end
    end

    widths = printed_columns.map{|row| row.flat_map{|c| c.map(&:length)}.max + col_padding}

    header + printed_columns.transpose.each_with_index.map do |row, index|
      height = row.map(&:length).max

      row = row.zip(widths).map do |cell, width|
        cell += [" "] * (height - cell.length)
        cell.map{|i| i.rjust(width)}
      end

      row = row.transpose.map{|i| i.join('')}.join("\n")

      if index == max_section
        row += "\n" + '-'*widths.reduce(:+)
      end
      row
    end.join("\n")
  rescue NoMethodError => e
    raise Exception.new(e)
  end

end<commit_msg>change some of the printable methods to module methods<commit_after>module ObjectTable::Printable

  def self.get_printable_column(name, column)
    padding = [nil] * (column.rank - 1)
    rows = column.shape[-1].times.map do |i|
      row = column[*padding, i]
      str = row.is_a?(NArray) ? row.inspect.partition("\n")[-1].strip : row.inspect
      str.split("\n")
    end

    name = name.to_s
    [[name]] + rows + [[name]]
  end

  def self.get_printable_line_numbers(numbers)
    rows = numbers.map do |i|
      ["#{i}: "]
    end

    [['']] + rows + [['']]
  end

  def inspect(max_section = 5, col_padding = 2)
    header = "#{self.class}(#{nrows}, #{ncols})\n"
    printed_columns = []

    if nrows > max_section * 2
      head = (0...max_section)
      tail = ((nrows - max_section)...nrows)

      printed_columns.push ObjectTable::Printable.get_printable_line_numbers(head.to_a + tail.to_a)

      printed_columns += columns.map do |name, c|
        padding = [nil] * (c.rank - 1)
        c = c.slice(*padding, [head, tail])
        ObjectTable::Printable.get_printable_column(name, c)
      end
    else
      max_section = -1
      printed_columns.push ObjectTable::Printable.get_printable_line_numbers(0...nrows)
      printed_columns += columns.map do |name, c|
        ObjectTable::Printable.get_printable_column(name, c)
      end
    end

    widths = printed_columns.map{|row| row.flat_map{|c| c.map(&:length)}.max + col_padding}

    header + printed_columns.transpose.each_with_index.map do |row, index|
      height = row.map(&:length).max

      row = row.zip(widths).map do |cell, width|
        cell += [" "] * (height - cell.length)
        cell.map{|i| i.rjust(width)}
      end

      row = row.transpose.map{|i| i.join('')}.join("\n")

      if index == max_section
        row += "\n" + '-'*widths.reduce(:+)
      end
      row
    end.join("\n")

  rescue NoMethodError => e
    raise Exception.new(e)
  end

end
{'fraction_non_alphanumeric': 0.1585949973390101, 'fraction_numerical': 0.005321979776476849, 'mean_word_length': 2.58, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2619804', 'n_tokens_mistral': 1363, 'n_tokens_neox': 1317, 'n_words': 269}