Class: Renogen::Formatters::MarkdownTable

Inherits:
Markdown show all
Defined in:
lib/renogen/formatters/markdown_table.rb

Overview

For formatting a change into markdown format

Instance Attribute Summary collapse

Attributes inherited from Base

#options

Instance Method Summary collapse

Methods inherited from Base

#initialize, register, #write_footer, #write_group_end

Constructor Details

This class inherits a constructor from Renogen::Formatters::Base

Instance Attribute Details

#headingsObject (readonly)

Returns the value of attribute headings.



8
9
10
# File 'lib/renogen/formatters/markdown_table.rb', line 8

def headings
  @headings
end

Instance Method Details

#header(changelog) ⇒ Object

Generate header

return [String]

Parameters:



19
20
21
22
23
24
25
26
27
# File 'lib/renogen/formatters/markdown_table.rb', line 19

def header(changelog)
  @headings = changelog.groups.keys
  [
    "# #{changelog.version} (#{changelog.date})",
    "",
    "| #{headings.join(' | ')} |",
    "| #{headings.map{|_| '-' }.join(' | ')} |"
  ].join("\n")
end

#table_formatter?Boolean

Returns:

  • (Boolean)


10
11
12
# File 'lib/renogen/formatters/markdown_table.rb', line 10

def table_formatter?
  true
end

#write_change(ticket) ⇒ String

Outputs a line or block as the body for a change in a group.

Parameters:

  • ticket (Hash<group: string>)

Returns:

  • (String)


49
50
51
52
53
54
55
# File 'lib/renogen/formatters/markdown_table.rb', line 49

def write_change(ticket)
  "| "+ @headings.map do |heading|
    value = ticket.fetch(heading, '-')
    value = value.join("\n") if value.is_a?(Array)
    value.gsub("\n", "<br>")
  end.join(' | ') + " |"
end

#write_group(group) ⇒ String

Outputs a line or block as a header for a group.

Parameters:

  • group (String)

Returns:

  • (String)


41
42
43
# File 'lib/renogen/formatters/markdown_table.rb', line 41

def write_group(group)
  "## #{group}\n\n"
end

#write_header(header) ⇒ String

Outputs a line or block of text appearing at the top of the change log.

Parameters:

  • header (String)

Returns:

  • (String)


33
34
35
# File 'lib/renogen/formatters/markdown_table.rb', line 33

def write_header(header)
  "#{header}\n"
end