class Asciidoctor::Table

It supports all three of AsciiDoc’s table formats: psv, dsv and csv.
Public: Methods and constants for managing AsciiDoc table content in a document.

def assign_column_widths width_base = nil, autowidth_cols = nil

returns nothing

width_base - the total of the relative column values used for calculating percentage widths (default: nil)

This method assumes there's at least one column in the columns array.

donates the balance to the final column.
This method rounds the percentage width values to 4 decimal places and

Internal: Assign column widths to columns
def assign_column_widths width_base = nil, autowidth_cols = nil
  precision = DEFAULT_PRECISION
  total_width = col_pcwidth = 0
  if width_base
    if autowidth_cols
      if width_base > 100
        autowidth = 0
        logger.warn %(total column width must not exceed 100% when using autowidth columns; got #{width_base}%)
      else
        autowidth = ((100.0 - width_base) / autowidth_cols.size).truncate precision
        autowidth = autowidth.to_i if autowidth.to_i == autowidth
        width_base = 100
      end
      autowidth_attrs = { 'width' => autowidth, 'autowidth-option' => '' }
      autowidth_cols.each {|col| col.update_attributes autowidth_attrs }
    end
    @columns.each {|col| total_width += (col_pcwidth = col.assign_width nil, width_base, precision) }
  else
    col_pcwidth = (100.0 / @columns.size).truncate precision
    col_pcwidth = col_pcwidth.to_i if col_pcwidth.to_i == col_pcwidth
    @columns.each {|col| total_width += col.assign_width col_pcwidth, nil, precision }
  end
  # donate balance, if any, to final column (using half up rounding)
  @columns[-1].assign_width(((100 - total_width + col_pcwidth).round precision), nil, precision) unless total_width == 100
  nil
end

def create_columns colspecs

returns nothing

Internal: Creates the Column objects from the column spec
def create_columns colspecs
  cols = []
  autowidth_cols = nil
  width_base = 0
  colspecs.each do |colspec|
    colwidth = colspec['width']
    cols << (Column.new self, cols.size, colspec)
    if colwidth < 0
      (autowidth_cols ||= []) << cols[-1]
    else
      width_base += colwidth
    end
  end
  if (num_cols = (@columns = cols).size) > 0
    @attributes['colcount'] = num_cols
    width_base = nil unless width_base > 0 || autowidth_cols
    assign_column_widths width_base, autowidth_cols
  end
  nil
end

def header_row?

the row being processed is (or is assumed to be) the header row, otherwise nil
Internal: Returns the current state of the header option (true or :implicit) if
def header_row?
  (val = @has_header_option) && @rows.body.empty? ? val : nil
end

def initialize parent, attributes

def initialize parent, attributes
  super parent, :table
  @rows = Rows.new
  @columns = []
  @has_header_option = false
  # smells like we need a utility method here
  # to resolve an integer width from potential bogus input
  if (pcwidth = attributes['width'])
    if (pcwidth_intval = pcwidth.to_i) > 100 || pcwidth_intval < 1
      pcwidth_intval = 100 unless pcwidth_intval == 0 && (pcwidth == '0' || pcwidth == '0%')
    end
  else
    pcwidth_intval = 100
  end
  @attributes['tablepcwidth'] = pcwidth_intval
  if @document.attributes['pagewidth']
    @attributes['tableabswidth'] = (abswidth_val = (((pcwidth_intval / 100.0) * @document.attributes['pagewidth'].to_f).truncate DEFAULT_PRECISION)) == abswidth_val.to_i ? abswidth_val.to_i : abswidth_val
  end
  @attributes['orientation'] = 'landscape' if attributes['rotate-option']
end

def partition_header_footer(attrs)

returns nothing

by the options on the table
Internal: Partition the rows into header, footer and body as determined
def partition_header_footer(attrs)
  # set rowcount before splitting up body rows
  num_body_rows = @attributes['rowcount'] = (body = @rows.body).size
  if num_body_rows > 0
    if @has_header_option
      @rows.head = [body.shift.map {|cell| cell.reinitialize true }]
      num_body_rows -= 1
    elsif @has_header_option.nil?
      @has_header_option = false
      body.unshift(body.shift.map {|cell| cell.reinitialize false })
    end
  end
  @rows.foot = [body.pop] if num_body_rows > 0 && attrs['footer-option']
  nil
end