Class: PmdTester::CpdReportDocument
- Inherits:
-
Nokogiri::XML::SAX::Document
- Object
- Nokogiri::XML::SAX::Document
- PmdTester::CpdReportDocument
- Defined in:
- lib/pmdtester/parsers/cpd_report_document.rb
Overview
Parses a CPD report XML file into a set of duplications and errors
Instance Attribute Summary collapse
-
#duplications ⇒ Object
readonly
Returns the value of attribute duplications.
-
#errors ⇒ Object
readonly
Returns the value of attribute errors.
Instance Method Summary collapse
- #cdata_block(string) ⇒ Object
- #characters(string) ⇒ Object
- #end_element(name) ⇒ Object
-
#initialize(branch_name, working_dir) ⇒ CpdReportDocument
constructor
A new instance of CpdReportDocument.
- #parse(file_path) ⇒ Object
- #start_element(name, attrs = []) ⇒ Object
Constructor Details
#initialize(branch_name, working_dir) ⇒ CpdReportDocument
Returns a new instance of CpdReportDocument.
9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/pmdtester/parsers/cpd_report_document.rb', line 9 def initialize(branch_name, working_dir) super() @duplications = [] @errors = [] @working_dir = working_dir @branch_name = branch_name @current_duplication = nil @current_error = nil @cur_text = String.new(capacity: 200) end |
Instance Attribute Details
#duplications ⇒ Object (readonly)
Returns the value of attribute duplications.
7 8 9 |
# File 'lib/pmdtester/parsers/cpd_report_document.rb', line 7 def duplications @duplications end |
#errors ⇒ Object (readonly)
Returns the value of attribute errors.
7 8 9 |
# File 'lib/pmdtester/parsers/cpd_report_document.rb', line 7 def errors @errors end |
Instance Method Details
#cdata_block(string) ⇒ Object
47 48 49 |
# File 'lib/pmdtester/parsers/cpd_report_document.rb', line 47 def cdata_block(string) @cur_text << string end |
#characters(string) ⇒ Object
43 44 45 |
# File 'lib/pmdtester/parsers/cpd_report_document.rb', line 43 def characters(string) @cur_text << string end |
#end_element(name) ⇒ Object
51 52 53 54 55 56 57 58 59 60 |
# File 'lib/pmdtester/parsers/cpd_report_document.rb', line 51 def end_element(name) case name when 'duplication' handle_end_duplication when 'codefragment' handle_end_codefragment when 'error' handle_end_error end end |
#parse(file_path) ⇒ Object
22 23 24 25 26 |
# File 'lib/pmdtester/parsers/cpd_report_document.rb', line 22 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
28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/pmdtester/parsers/cpd_report_document.rb', line 28 def start_element(name, attrs = []) attrs = attrs.to_h case name when 'duplication' handle_start_duplication attrs when 'file' handle_start_file attrs when 'codefragment' handle_start_codefragment when 'error' handle_start_error attrs end end |