Class: Ruport::Formatter::MarkDown

Inherits:
Ruport::Formatter show all
Defined in:
lib/ruport/formatter/markdown.rb

Overview

This class produces Markdown table output from Ruport::Table data.

Rendering Options

:alignment: Default alignment for all columns. Allowed values are :left, :center and :right. Default is :left.

:column_alignments: Alignments for specific columns. You can configure alignments by using Hash (key: column name, value: alignment)

Instance Attribute Summary

Attributes inherited from Ruport::Formatter

#data, #format, #options

Instance Method Summary collapse

Methods inherited from Ruport::Formatter

build, #clear_output, #erb, formats, #method_missing, #output, renders, save_as_binary_file, #save_output, #template

Methods included from RenderingTools

#render_group, #render_grouping, #render_inline_grouping, #render_row, #render_table

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Ruport::Formatter

Instance Method Details

#apply_templateObject

Hook for setting available options using a template.



17
18
19
# File 'lib/ruport/formatter/markdown.rb', line 17

def apply_template
  apply_table_format_template(template.table)
end

#build_table_bodyObject

Generates body of Markdown table data. Following characters will be replaced as escape.

  • | -> |

  • newline code(\n) -> <br>



36
37
38
39
40
41
42
43
44
# File 'lib/ruport/formatter/markdown.rb', line 36

def build_table_body
  body =
    if data.column_names && !data.column_names.empty?
      data
    else
      data[1..-1]
    end
  body.each { |row| build_md_row(output, row) }
end

#build_table_headerObject

Uses the column names from the given Data::Table to generate a table header. If no column names are given, first row will be treated as table header.



25
26
27
28
29
# File 'lib/ruport/formatter/markdown.rb', line 25

def build_table_header
  names = column_names(data)
  build_md_row(output, names)
  build_md_row(output, alignment_strings(names))
end