class TextToCheckstyle::Converter

Constants

ERROR_COLUMN
ERROR_LINE
ERROR_SEVERITY
ERROR_SOURCE
FILE_NAME

Public Class Methods

convert(text, options = {}) click to toggle source
# File lib/text_to_checkstyle/converter.rb, line 8
def self.convert(text, options = {})
  fail NoInputError if !text || text.empty?
  logger.info(text: text)

  doc = REXML::Document.new
  doc.add REXML::XMLDecl.new
  checkstyle = doc.add_element 'checkstyle'
  name = options[:name] || FILE_NAME
  file = checkstyle.add_element 'file', 'name' => name
  line = options[:line] || ERROR_LINE
  column = options[:column] || ERROR_COLUMN
  severity = options[:severity] || ERROR_SEVERITY
  message = text
  source = options[:source] || ERROR_SOURCE
  file.add_element 'error',
                   'line' => line,
                   'column' => column,
                   'severity' => severity,
                   'message' => message,
                   'source' => source
  doc.to_s
end
logger() click to toggle source
# File lib/text_to_checkstyle/converter.rb, line 30
def self.logger
  ::TextToCheckstyle.logger
end