Sha256: 4a1f5089dc667b8f36282fd44b950264b7e0eec62832bc2f8d65d135d57e2e91
Contents?: true
Size: 1.35 KB
Versions: 2
Compression:
Stored size: 1.35 KB
Contents
# frozen_string_literal: true module Quality # Class processes output from a code quality command, tweaking it # for editor output and counting the number of violations found class CommandOutputProcessor attr_accessor :emacs_format, :file attr_reader :found_output, :violations def initialize @emacs_format = false @found_output = false @violations = 0 end def process(&count_violations_on_line) process_file(file, &count_violations_on_line) end private def process_file(file, &count_violations_on_line) out = '' out += process_line(&count_violations_on_line) while (@current_line = file.gets) out end def processed_output if emacs_format preprocess_line_for_emacs else @current_line end end def process_line(&block) @found_output = true @violations += if block yield @current_line else 1 end processed_output end def preprocess_line_for_emacs case @current_line when /^ *(\S*.rb:[0-9]*) *(.*)/ "#{Regexp.last_match[1]}: #{Regexp.last_match[2]}\n" when /^ *(.*) +(\S*.rb:[0-9]*) *(.*)/ "#{Regexp.last_match[2]}: #{Regexp.last_match[1]}\n" else @current_line end end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
quality-40.0.1 | lib/quality/command_output_processor.rb |
quality-40.0.0 | lib/quality/command_output_processor.rb |