class Dox::Printers::BasePrinter

Attributes

spec[R]

Public Class Methods

new(spec) click to toggle source
# File lib/dox/printers/base_printer.rb, line 8
def initialize(spec)
  @spec = spec || {}
end

Public Instance Methods

find_or_add(hash, key, default = {}) click to toggle source
# File lib/dox/printers/base_printer.rb, line 16
def find_or_add(hash, key, default = {})
  return hash[key] if hash.key?(key)

  hash[key] = default
end
format_desc(description) click to toggle source
# File lib/dox/printers/base_printer.rb, line 48
def format_desc(description)
  desc = description
  desc = '' if desc.nil?
  desc = read_file(desc) if desc.end_with?('.md')

  desc
end
formatted_body(body_str, content_type) click to toggle source
# File lib/dox/printers/base_printer.rb, line 28
def formatted_body(body_str, content_type)
  case content_type
  when %r{application\/.*json}
    JSON.parse(body_str)
  when /xml/
    pretty_xml(body_str)
  else
    body_str
  end
end
pretty_xml(xml_string) click to toggle source
# File lib/dox/printers/base_printer.rb, line 39
def pretty_xml(xml_string)
  doc = REXML::Document.new(xml_string)
  formatter = REXML::Formatters::Pretty.new
  formatter.compact = true
  result = ''
  formatter.write(doc, result)
  result
end
print() click to toggle source
read_file(path, root_path: Dox.config.descriptions_location) click to toggle source
# File lib/dox/printers/base_printer.rb, line 22
def read_file(path, root_path: Dox.config.descriptions_location)
  return '' unless root_path

  File.read(File.join(root_path, path))
end