class

Table

Inherits Reference < Object

Constructors

new(data : Array(Array(String | Nil)) = Array(Array(String | Nil)).new)

Can be initialized with an of cells: Array(Array(String | Nil)) or nothing and you can add rows of data later with add_rows Note: all rows of data must be the same length.

Source
new(columns : Array(Column))

Allows you to initialize this with an array of columns. Note: when this initializer is used you will not be able to use the add_rows method

Source

Instance methods

add_row(row : Array(String | Nil))

Adds a row of data. Note: this must have the same number of items as all the other rows that have been added.

Source
data
Source
data=(data : Array(Array(Nil | String)))
Source
extract_columns(data : Array(Array(String | Nil))) : Array(Column)

Extracts Column objects from the provided data primarily for use use by this class, but you may find it useful too.

Source
format(options : Hash(Symbol, String | Bool) = Hash(Symbol, String | Bool).new) : String

Formats the data into a textual table. By default it will:

  • start each row with "| "
  • end each row with " |"
  • separate each item with " | " These defaults can be overridden by specifying :left_border, :right_border, or :divider (respectively) in the options.

By default it assumes the first row is a header. To disable the divider under the first row set options[:show_header] = false To change the character used for the divider set options[:header_divider] = <any single character>

Example: [["things", "stuff"],["a", "b"], ["c", nil]] Would become

thingsstuff
ab
c
Source
width

Tells you how wide the table is

Source