Class: PmdTester::PmdReportDocument
- Inherits:
-
Nokogiri::XML::SAX::Document
- Object
- Nokogiri::XML::SAX::Document
- PmdTester::PmdReportDocument
- Defined in:
- lib/pmdtester/parsers/pmd_report_document.rb
Overview
This class is used for registering types of events you are interested in handling. Also see: www.rubydoc.info/github/sparklemotion/nokogiri/Nokogiri/XML/SAX/Document
Instance Attribute Summary collapse
-
#configerrors ⇒ Object
readonly
Returns the value of attribute configerrors.
-
#errors ⇒ Object
readonly
Returns the value of attribute errors.
-
#violations ⇒ Object
readonly
Returns the value of attribute violations.
Instance Method Summary collapse
- #cdata_block(string) ⇒ Object
- #characters(string) ⇒ Object
- #end_element(name) ⇒ Object
-
#initialize(branch_name, working_dir, filter_set = nil) ⇒ PmdReportDocument
constructor
A new instance of PmdReportDocument.
- #parse(file_path) ⇒ Object
- #start_element(name, attrs = []) ⇒ Object
Constructor Details
#initialize(branch_name, working_dir, filter_set = nil) ⇒ PmdReportDocument
Returns a new instance of PmdReportDocument.
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/pmdtester/parsers/pmd_report_document.rb', line 12 def initialize(branch_name, working_dir, filter_set = nil) super() @violations = CollectionByFile.new @errors = CollectionByFile.new @configerrors = Hash.new { |hash, key| hash[key] = [] } @current_violations = [] @current_violation = nil @current_error = nil @current_configerror = nil @filter_set = filter_set @working_dir = working_dir @branch_name = branch_name @cur_text = String.new(capacity: 200) end |
Instance Attribute Details
#configerrors ⇒ Object (readonly)
Returns the value of attribute configerrors.
10 11 12 |
# File 'lib/pmdtester/parsers/pmd_report_document.rb', line 10 def configerrors @configerrors end |
#errors ⇒ Object (readonly)
Returns the value of attribute errors.
9 10 11 |
# File 'lib/pmdtester/parsers/pmd_report_document.rb', line 9 def errors @errors end |
#violations ⇒ Object (readonly)
Returns the value of attribute violations.
8 9 10 |
# File 'lib/pmdtester/parsers/pmd_report_document.rb', line 8 def violations @violations end |
Instance Method Details
#cdata_block(string) ⇒ Object
54 55 56 |
# File 'lib/pmdtester/parsers/pmd_report_document.rb', line 54 def cdata_block(string) @cur_text << string end |
#characters(string) ⇒ Object
50 51 52 |
# File 'lib/pmdtester/parsers/pmd_report_document.rb', line 50 def characters(string) @cur_text << string end |
#end_element(name) ⇒ Object
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/pmdtester/parsers/pmd_report_document.rb', line 58 def end_element(name) case name when 'file' @violations.add_all(@current_filename, @current_violations) @current_filename = nil when 'violation' if match_filter_set?(@current_violation) @current_violation. = finish_text! @current_violations.push(@current_violation) end @current_violation = nil when 'error' @current_error.stack_trace = finish_text! @errors.add_all(@current_filename, [@current_error]) @current_filename = nil @current_error = nil when 'configerror' @configerrors[@current_configerror.rulename].push(@current_configerror) @current_configerror = nil end @cur_text.clear end |
#parse(file_path) ⇒ Object
29 30 31 32 33 |
# File 'lib/pmdtester/parsers/pmd_report_document.rb', line 29 def parse(file_path) parser = Nokogiri::XML::SAX::Parser.new(self) parser.parse(File.open(file_path)) if File.exist?(file_path) self end |
#start_element(name, attrs = []) ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/pmdtester/parsers/pmd_report_document.rb', line 35 def start_element(name, attrs = []) attrs = attrs.to_h case name when 'file' handle_start_file attrs when 'violation' handle_start_violation attrs when 'error' handle_start_error attrs when 'configerror' handle_start_configerror attrs end end |