class RspecOverview::Output::MarkdownTable
Constants
- BORDER_SEPERATOR
- HEADING_SEPERATOR
- NOT_BORDER_SEPERATOR
Attributes
matrix[R]
Public Class Methods
new(headings:, rows:)
click to toggle source
# File lib/rspec_overview/output/markdown_table.rb, line 10 def initialize(headings:, rows:) @matrix = Matrix.rows([headings] + rows) end
Public Instance Methods
column(index)
click to toggle source
# File lib/rspec_overview/output/markdown_table.rb, line 18 def column(index) matrix.column(index).to_a end
to_s()
click to toggle source
# File lib/rspec_overview/output/markdown_table.rb, line 14 def to_s render_table end
Private Instance Methods
create_heading_divider(line)
click to toggle source
# File lib/rspec_overview/output/markdown_table.rb, line 42 def create_heading_divider(line) line.gsub(NOT_BORDER_SEPERATOR, HEADING_SEPERATOR) end
pad_value(value, column_index)
click to toggle source
# File lib/rspec_overview/output/markdown_table.rb, line 46 def pad_value(value, column_index) column_width = width_of_column(column_index) value.to_s.ljust(column_width, " ") end
render_row(data_row)
click to toggle source
# File lib/rspec_overview/output/markdown_table.rb, line 32 def render_row(data_row) table_row = [BORDER_SEPERATOR] data_row.each_with_index do |value, column_index| table_row << " #{pad_value(value, column_index)} #{BORDER_SEPERATOR}" end table_row.join end
render_table()
click to toggle source
# File lib/rspec_overview/output/markdown_table.rb, line 26 def render_table lines = matrix.row_vectors.map(&method(:render_row)) lines.insert(1, create_heading_divider(lines.first)) lines.join("\n") + "\n" end
width_of_column(index)
click to toggle source
# File lib/rspec_overview/output/markdown_table.rb, line 51 def width_of_column(index) column(index).max_by{ |value| value.to_s.length }.length end