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
Public: Get/Set the columns for this table
Public: Boolean specifies whether this table has a header row
Public: Get/Set the Rows struct for this table (encapsulates head, foot and body rows)
Public Class Methods
# File lib/asciidoctor/table.rb, line 70 def initialize parent, attributes super parent, :table @rows = Rows.new @columns = [] @has_header_option = attributes.key? 'header-option' # smell 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.key? 'pagewidth' @attributes['tableabswidth'] ||= ((@attributes['tablepcwidth'].to_f / 100) * @document.attributes['pagewidth']).round end attributes['orientation'] = 'landscape' if attributes.key? 'rotate-option' end
Public Instance Methods
Internal: Assign column widths to columns
This method rounds the percentage width values to 4 decimal places and donates the balance to the final column.
This method assumes there's at least one column in the columns array.
width_base - the total of the relative column values used for calculating percentage widths (default: nil)
returns nothing
# File lib/asciidoctor/table.rb, line 129 def assign_column_widths width_base = nil pf = 10.0 ** 4 # precision factor (multipler / divisor) for managing precision of calculated result total_width = col_pcwidth = 0 if width_base @columns.each {|col| total_width += (col_pcwidth = col.assign_width nil, width_base, pf) } else col_pcwidth = ((100 * pf / @columns.size).to_i) / pf col_pcwidth = col_pcwidth.to_i if col_pcwidth.to_i == col_pcwidth @columns.each {|col| total_width += col.assign_width col_pcwidth } end # donate balance, if any, to final column @columns[-1].assign_width(((100 - total_width + col_pcwidth) * pf).round / pf) unless total_width == 100 nil end
Internal: Creates the Column objects from the column spec
returns nothing
# File lib/asciidoctor/table.rb, line 105 def create_columns colspecs cols = [] width_base = 0 colspecs.each do |colspec| width_base += colspec['width'] cols << (Column.new self, cols.size, colspec) end unless (@columns = cols).empty? @attributes['colcount'] = cols.size assign_column_widths(width_base == 0 ? nil : width_base) end nil end
Internal: Returns whether the current row being processed is the header row
# File lib/asciidoctor/table.rb, line 98 def header_row? @has_header_option && @rows.body.empty? end