Class: CodeCoverage::MarkdownTable
- Inherits:
-
Object
- Object
- CodeCoverage::MarkdownTable
- Defined in:
- lib/code_coverage/markdown_table.rb
Overview
Generate a markdown table.
Constant Summary collapse
- COLUMN_SEPARATOR =
'|'
- HEADER_SEPARATOR =
'-'
Instance Method Summary collapse
-
#header(*args) ⇒ Object
Add each entry to the table header.
-
#initialize ⇒ MarkdownTable
constructor
Initialize table generator.
-
#line(*args) ⇒ Object
Add a new line entry to the table.
-
#size ⇒ Integer
Return the number of lines without header items.
-
#to_markdown ⇒ String
Combine all data to a markdown table string.
Constructor Details
#initialize ⇒ MarkdownTable
Initialize table generator.
10 11 12 13 14 |
# File 'lib/code_coverage/markdown_table.rb', line 10 def initialize @header = COLUMN_SEPARATOR.dup @header_separator = COLUMN_SEPARATOR.dup @lines = [] end |
Instance Method Details
#header(*args) ⇒ Object
Add each entry to the table header
17 18 19 20 21 22 23 24 25 26 |
# 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) ⇒ Object
Add a new line entry to the table.
38 39 40 41 42 43 44 |
# 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 ⇒ Integer
Return the number of lines without header items.
31 32 33 |
# File 'lib/code_coverage/markdown_table.rb', line 31 def size @lines.length end |
#to_markdown ⇒ String
Combine all data to a markdown table string.
48 49 50 51 |
# File 'lib/code_coverage/markdown_table.rb', line 48 def to_markdown result = +"#{@header}\n#{@header_separator}\n" result << @lines.join("\n") end |