class PreCommit::Message::Extractor
Responsible for extract error messages from terminal output
Public Instance Methods
extract(terminal_output)
click to toggle source
Extract data from a XML formatted terminal_output
@param terminal_output [String] XML formatted terminal ouput @return [Domain::Checkstyle] The checkstyle
# File lib/plugins/pre_commit/message/extractor.rb, line 15 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 Instance Methods
bad_file(file)
click to toggle source
# File lib/plugins/pre_commit/message/extractor.rb, line 38 def bad_file(file) Domain::BadFile.new(file['name'], extract_errors(file)) end
blank?(value)
click to toggle source
# File lib/plugins/pre_commit/message/extractor.rb, line 48 def blank?(value) value.nil? || value.empty? end
extract_bad_file(xml_files)
click to toggle source
# File lib/plugins/pre_commit/message/extractor.rb, line 33 def extract_bad_file(xml_files) return [bad_file(xml_files)] unless xml_files.is_a? Array xml_files.map { |e| bad_file(e) } end
extract_errors(file)
click to toggle source
# File lib/plugins/pre_commit/message/extractor.rb, line 42 def extract_errors(file) return [] if blank? file['error'] return [file['error']] unless file['error'].is_a? Array file['error'] end
xml_content_of(raw_output)
click to toggle source
# File lib/plugins/pre_commit/message/extractor.rb, line 29 def xml_content_of(raw_output) raw_output[/<(.*)>/m] end