class Asciidoctor::Table

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

Constants

ALIGNMENTS

Public: A Hash mapping alignment abbreviations to alignments (horizontal and vertial) that can be applies to a table column or cell

DATA_FORMATS

Public: An Array of String keys that represent the table formats in AsciiDoc

DEFAULT_DATA_FORMAT

Public: A String key that specifies the default table format in AsciiDoc (psv)

DEFAULT_DELIMITERS

Public: A Hash mapping the AsciiDoc table formats to their default delimiters

TEXT_STYLES

Public: A Hash mapping styles abbreviations to styles that can be applied to a table column or cell

Attributes

columns[RW]

Public: Get/Set the columns for this table

has_header_option[RW]

Public: Boolean specifies whether this table has a header row

rows[RW]

Public: Get/Set the Rows struct for this table (encapsulates head, foot and body rows)

Public Class Methods

new(parent, attributes) click to toggle source
Calls superclass method Asciidoctor::AbstractBlock.new
# File lib/asciidoctor/table.rb, line 70
def initialize parent, attributes
  super parent, :table
  @rows = Rows.new
  @columns = []

  @has_header_option = attributes.has_key? 'header-option'

  # smell like we need a utility method here
  # to resolve an integer width from potential bogus input
  pcwidth = attributes['width']
  pcwidth_intval = pcwidth.to_i.abs
  if pcwidth_intval == 0 && pcwidth != '0' || pcwidth_intval > 100
    pcwidth_intval = 100
  end
  @attributes['tablepcwidth'] = pcwidth_intval

  if @document.attributes.has_key? 'pagewidth'
    @attributes['tableabswidth'] ||=
        ((@attributes['tablepcwidth'].to_f / 100) * @document.attributes['pagewidth']).round
  end
end

Public Instance Methods

create_columns(col_specs) click to toggle source

Internal: Creates the Column objects from the column spec

returns nothing

# File lib/asciidoctor/table.rb, line 101
def create_columns(col_specs)
  total_width = 0
  cols = []
  col_specs.each do |col_spec|
    total_width += col_spec['width']
    cols << Column.new(self, cols.size, col_spec)
  end

  unless cols.empty?
    @attributes['colcount'] = cols.size
    even_width = (100.0 / cols.size).floor
    cols.each {|c| c.assign_width(total_width, even_width) }
  end

  @columns = cols
  nil
end
header_row?() click to toggle source

Internal: Returns whether the current row being processed is the header row

# File lib/asciidoctor/table.rb, line 94
def header_row?
  @has_header_option && @rows.body.empty?
end