Class: TextToCheckstyle::Converter

Inherits:
Object
  • Object
show all
Defined in:
lib/text_to_checkstyle/converter.rb

Constant Summary collapse

FILE_NAME =
'path/to/file'
ERROR_LINE =
'0'
ERROR_COLUMN =
'0'
ERROR_SEVERITY =
'info'
ERROR_SOURCE =
'TextToCheckstyle'

Class Method Summary collapse

Class Method Details

.convert(text, options = {}) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# 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

.loggerObject



30
31
32
# File 'lib/text_to_checkstyle/converter.rb', line 30

def self.logger
  ::TextToCheckstyle.logger
end