class CodeCoverage::MarkdownTable
Generate a markdown table.
Constants
- COLUMN_SEPARATOR
- HEADER_SEPARATOR
Public Class Methods
new()
click to toggle source
Initialize table generator.
# File lib/code_coverage/markdown_table.rb, line 10 def initialize @header = COLUMN_SEPARATOR.dup @header_separator = COLUMN_SEPARATOR.dup @lines = [] end
Public Instance Methods
header(*args)
click to toggle source
Add each entry to the table header
# File lib/code_coverage/markdown_table.rb, line 17 def header(*args) args.each_with_index do |item, index| @header << "#{item}#{COLUMN_SEPARATOR}" @header_separator << if index.zero? ":#{HEADER_SEPARATOR}#{COLUMN_SEPARATOR}" else ":#{HEADER_SEPARATOR}:#{COLUMN_SEPARATOR}" end end end
line(*args)
click to toggle source
Add a new line entry to the table.
@param args [String]* Multiple comma separated strings for each column entry.
# File lib/code_coverage/markdown_table.rb, line 38 def line(*args) line = COLUMN_SEPARATOR.dup args.each do |item| line << "#{item}#{COLUMN_SEPARATOR}" end @lines << line end
size()
click to toggle source
Return the number of lines without header items.
@return [Integer] Number of lines.
# File lib/code_coverage/markdown_table.rb, line 31 def size @lines.length end
to_markdown()
click to toggle source
Combine all data to a markdown table string. @return [String] Table.
# File lib/code_coverage/markdown_table.rb, line 48 def to_markdown result = +"#{@header}\n#{@header_separator}\n" result << @lines.join("\n") end