Sha256: 2427c53f708072d52eb4ed5d459dfa4fda3e1bc7541509eca6c65ef822d053ae
Contents?: true
Size: 1.2 KB
Versions: 1
Compression:
Stored size: 1.2 KB
Contents
require 'crack' require_relative '../domain/checkstyle' require_relative '../domain/bad_file' module PreCommit module Message ## # Responsible for extract error messages from terminal output class Extractor ## # Extract data from a XML formatted +output+ # # @param output [String] Xml formatted ouput # @return [Hash] def extract(output) return Domain::Checkstyle.good if output.nil? || output.empty? xml_data = Crack::XML.parse(xml_content(output)) files = xml_data['checkstyle']['file'] Domain::Checkstyle.new(extract_bad_file(files)) end private def xml_content(raw_output) raw_output[/<(.*)>/m] end def extract_bad_file(xml_files) return [create_bad_file(xml_files)] unless xml_files.is_a? Array xml_files.reduce([]) { |a, e| a.push(create_bad_file(e)) } end def create_bad_file(file) Domain::BadFile.new(file['name'], extract_errors(file['error'])) end def extract_errors(xml_errors) return [] if xml_errors.nil? || xml_errors.empty? return [xml_errors] unless xml_errors.is_a? Array xml_errors end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
java-checkstyle-1.0.3 | lib/plugins/pre-commit/message/extractor.rb |