<commit_before>##
# Define column and related constructs
module Tablet
  ##
  # Column object
  class Column
    addr_reader :name, :title, :weight, :width:q
  end
end<commit_msg>define basic column<commit_after>##
# Define column and related constructs
module Tablet
  DEFAULT_WIDTH_CALC = proc { |rows| rows.max_by(&:length) }
  DEFAULT_FORMATTER = proc { |row, size| row.slice(0, size) }

  ##
  # Column object
  class Column
    attr_reader :name, :title, :weight

    def initialize(params = {})
      @options = params
    end

    def name
      @name ||= (@params[:name] || @params[:title] || object_id.to_s).to_sym
    end

    def title
      @title ||= params[:title] || ''
    end

    def weight
      @weight ||= params[:weight] || 0
    end

    def width_calc
      @width_calc ||= params[:width] || DEFAULT_WIDTH_CALC
    end

    def formatter
      @formatter ||= params[:formatter] || DEFAULT_FORMATTER
    end

    def resize!(rows)
      @width = parse_size(rows)
    end

    def format(row)
      params[:formatter].call(row, @size)
    end

    private

    def parse_size(rows)
      return @width_calc.call(rows) if @width_calc.respond_to? :call
      if @width_calc.is_a?(Enumerable)
        if @width_calc.all? { |x| x.is_a? Integer }
          return @width_calc.to_a.sort.reverse
        else
          fail ArgumentError, 'Non-integer widths provided'
        end
      end
      fail ArgumentError, 'Width-calc must evaluate to an array of integers'
    end
  end
end
{'fraction_non_alphanumeric': 0.11259160559626916, 'fraction_numerical': 0.0013324450366422385, 'mean_word_length': 2.708641975308642, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '768850', 'n_tokens_mistral': 491, 'n_tokens_neox': 472, 'n_words': 129}