class Table
- Table
- Reference
- Object
Defined in:
crystal_fmt/table.crConstructors
-
.new(data : Array(Array(String?)) = 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.
-
.new(columns : Array(Column))
Allows you to initialize this with an array of columns.
Instance Method Summary
-
#add_row(row : Array(String?))
Adds a row of data.
- #data : Array(Array(String?))
- #data=(data)
-
#extract_columns(data : Array(Array(String?))) : Array(Column)
Extracts Column objects from the provided data primarily for use use by this class, but you may find it useful too.
-
#format(options : Hash(Symbol, String | Bool) = Hash(Symbol, String | Bool).new) : String
Formats the data into a textual table.
-
#width : Int32
Tells you how wide the table is
Constructor Detail
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.
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
Instance Method Detail
Adds a row of data. Note: this must have the same number of items as all the other rows that have been added.
Extracts Column objects from the provided data primarily for use use by this class, but you may find it useful too.
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 | things | stuff | | ------ | ----- | | a | b | | c | |