Module: Jekyll::DatabaseTables::Formatter::Helpers
- Included in:
- PsqlFormatter
- Defined in:
- lib/jekyll-database-tables/formatters.rb
Overview
Optional mixin providing geometry utilities for formatter subclasses.
Include this modules to gain access to #column_widths, which is useful for any formatter that needs to align output by column.
Instance Method Summary collapse
-
#column_widths(table) ⇒ Array<Integer>
Computes the minimum column widths needed to fit all cell values.
Instance Method Details
#column_widths(table) ⇒ Array<Integer>
Computes the minimum column widths needed to fit all cell values.
21 22 23 24 25 26 27 28 |
# File 'lib/jekyll-database-tables/formatters.rb', line 21 def column_widths(table) col_count = table.headers.length all_rows = [table.headers] + table.rows.map(&:cells) (0...col_count).map do |index| all_rows.map { |row| row[index].to_s.length }.max end end |