lib/plugins/pre-commit/message/extractor.rb in java-checkstyle-1.0.3 vs lib/plugins/pre-commit/message/extractor.rb in java-checkstyle-1.0.4
- old
+ new
@@ -6,43 +6,48 @@
module Message
##
# Responsible for extract error messages from terminal output
class Extractor
##
- # Extract data from a XML formatted +output+
+ # Extract data from a XML formatted +terminal_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))
+ # @param terminal_output [String] XML formatted terminal ouput
+ # @return [Domain::Checkstyle] The checkstyle
+ def extract(terminal_output)
+ if blank?(terminal_output) ||
+ blank?(xml_content_of(terminal_output))
+ return Domain::Checkstyle.good
+ end
+ xml_data = Crack::XML.parse(xml_content_of(terminal_output))
files = xml_data['checkstyle']['file']
Domain::Checkstyle.new(extract_bad_file(files))
end
private
- def xml_content(raw_output)
+ def xml_content_of(raw_output)
raw_output[/<(.*)>/m]
end
def extract_bad_file(xml_files)
- return [create_bad_file(xml_files)] unless xml_files.is_a? Array
+ return [bad_file(xml_files)] unless xml_files.is_a? Array
+ xml_files.map { |e| bad_file(e) }
+ end
- xml_files.reduce([]) { |a, e| a.push(create_bad_file(e)) }
+ def bad_file(file)
+ Domain::BadFile.new(file['name'], extract_errors(file))
end
- def create_bad_file(file)
- Domain::BadFile.new(file['name'], extract_errors(file['error']))
+ def extract_errors(file)
+ return [] if blank? file['error']
+ return [file['error']] unless file['error'].is_a? Array
+ 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
+ def blank?(value)
+ value.nil? || value.empty?
end
end
end
end