Class: CovLoupe::CoverageTableFormatter
- Inherits:
-
Object
- Object
- CovLoupe::CoverageTableFormatter
- Defined in:
- lib/cov_loupe/coverage/coverage_table_formatter.rb
Overview
Formats coverage data as a table with Unicode box-drawing or ASCII borders.
Used by CoverageModel#format_table for the default cov-loupe list output.
Column widths are computed dynamically from the data. The table includes:
- File path from each row
- Coverage percentage
- Covered lines
- Total lines
- Staleness indicator
A footer row summarizes file counts (total, ok, stale).
Class Method Summary collapse
-
.format(rows, output_chars: :default) ⇒ String
Format coverage rows as a table with box-drawing or ASCII characters.
Class Method Details
.format(rows, output_chars: :default) ⇒ String
Format coverage rows as a table with box-drawing or ASCII characters.
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/cov_loupe/coverage/coverage_table_formatter.rb', line 24 def self.format(rows, output_chars: :default) return 'No coverage data found' if rows.empty? # Resolve mode and get appropriate charset resolved_mode = OutputChars.resolve_mode(output_chars) charset = OutputChars.charset_for(resolved_mode) # Convert file paths and other string content to ASCII if needed converted_rows = rows.map do |row| row.merge('file' => OutputChars.convert(row['file'], resolved_mode)) end widths = compute_table_widths(converted_rows) lines = [] lines << border_line(widths, charset[:top_left], charset[:top_tee], charset[:top_right], charset) lines << header_row(widths, charset) lines << border_line(widths, charset[:left_tee], charset[:cross], charset[:right_tee], charset) converted_rows.each { |file_data| lines << data_row(file_data, widths, charset) } lines << border_line(widths, charset[:bottom_left], charset[:bottom_tee], charset[:bottom_right], charset) lines << summary_counts(converted_rows) if converted_rows.any? { |f| StaleStatus.stale?(f['stale']) } lines << 'Staleness: error, missing, newer, length_mismatch' end lines.join("\n") end |