class Dogcatcher::Markdown

Produces a string formatted as Markdown.

Public Class Methods

new() click to toggle source
# File lib/dogcatcher/markdown.rb, line 4
def initialize
  @result = []
end

Public Instance Methods

bullet(str) click to toggle source

Adds a bullet point to the result string.

@param [String] str text to include next to the bullet point

# File lib/dogcatcher/markdown.rb, line 11
def bullet(str)
  @result << ['* ', str, "\n"]
end
code_block(str, language = nil, max_len = -1) click to toggle source

Adds a code block to the result string.

@param [String] str text to include in the code block @param [String] language of the code block @param [FixNum] max_len Length at which to truncate the content of the

code block. Length includes block backticks and language. Negative
numbers disable the maximum length.
# File lib/dogcatcher/markdown.rb, line 22
def code_block(str, language = nil, max_len = -1)
  if max_len > 0
    max_len -= code_block_builder('', language).length # Subtract markdown overhead
    str = str[0..max_len-1] if str.length > max_len
  end
  @result << code_block_builder(str, language)
end
result() click to toggle source

Gets the result string formatted in Markdown.

@return [String]

# File lib/dogcatcher/markdown.rb, line 33
def result
  ['%%%', "\n", *@result, "\n", '%%%'].join('')
end

Private Instance Methods

code_block_builder(str, language) click to toggle source
# File lib/dogcatcher/markdown.rb, line 39
def code_block_builder(str, language)
  ['```', language, "\n", str, "\n```\n"].join('')
end