Class: SimpleCovMcp::TableFormatter
- Inherits:
-
Object
- Object
- SimpleCovMcp::TableFormatter
- Defined in:
- lib/simplecov_mcp/table_formatter.rb
Overview
General-purpose table formatter with box-drawing characters Used by commands to create consistent formatted output
Class Method Summary collapse
-
.format(headers:, rows:, alignments: nil) ⇒ String
Format data as a table with box-drawing characters.
-
.format_vertical(data) ⇒ String
Format a single key-value table (vertical layout).
Class Method Details
.format(headers:, rows:, alignments: nil) ⇒ String
Format data as a table with box-drawing characters
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/simplecov_mcp/table_formatter.rb', line 12 def self.format(headers:, rows:, alignments: nil) return 'No data to display' if rows.empty? alignments ||= [:left] * headers.size all_rows = [headers] + rows.map { |row| row.map(&:to_s) } # Calculate column widths widths = headers.size.times.map do |col| all_rows.map { |row| row[col].to_s.length }.max end lines = [] lines << border_line(widths, '┌', '┬', '┐') lines << data_row(headers, widths, alignments) lines << border_line(widths, '├', '┼', '┤') rows.each { |row| lines << data_row(row, widths, alignments) } lines << border_line(widths, '└', '┴', '┘') lines.join("\n") end |
.format_vertical(data) ⇒ String
Format a single key-value table (vertical layout)
36 37 38 39 |
# File 'lib/simplecov_mcp/table_formatter.rb', line 36 def self.format_vertical(data) rows = data.map { |k, v| [k.to_s, v.to_s] } format(headers: ['Key', 'Value'], rows: rows, alignments: [:left, :left]) end |