Method: CLI::UI::Table.capture_table
- Defined in:
- lib/cli/ui/table.rb
.capture_table(table, col_spacing: 1) ⇒ Object
Captures a table’s output as an array of strings without printing to the terminal Can be used to further manipulate or format the table output
Attributes
-
table- (required) 2D array of strings representing the table data
Options
-
:col_spacing- Number of spaces between columns. Defaults to 1
Returns
-
Array[String]- Array of strings, each representing a row of the formatted table
Example
CLI::UI::Table.capture_table([
["{{bold:header_1}}", "{{bold:header_2}}"],
["really_long_cell", "short"],
["row2", "row2"]
])
: (Array[Array] table, ?col_spacing: Integer) -> Array
75 76 77 78 79 |
# File 'lib/cli/ui/table.rb', line 75 def capture_table(table, col_spacing: 1) strio = StringIO.new puts_table(table, col_spacing: col_spacing, to: strio) strio.string.lines.map(&:chomp) end |