Sha256: 34a459641ee8840b6057125f6db8b81b488681f5e7d42885ecbfa9e00e4cd077

Contents?: true

Size: 1.42 KB

Versions: 27

Compression:

Stored size: 1.42 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
    attr_accessor :file
    attr_reader :found_output
    attr_reader :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 = ''
      while (@current_line = file.gets)
        out += process_line(&count_violations_on_line)
      end
      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
      if @current_line =~ /^ *(\S*.rb:[0-9]*) *(.*)/
        Regexp.last_match[1] + ': ' + Regexp.last_match[2] + "\n"
      elsif @current_line =~ /^ *(.*) +(\S*.rb:[0-9]*) *(.*)/
        Regexp.last_match[2] + ': ' + Regexp.last_match[1] + "\n"
      else
        @current_line
      end
    end
  end
end

Version data entries

27 entries across 27 versions & 1 rubygems

Version Path
quality-37.1.1 lib/quality/command_output_processor.rb
quality-37.1.0 lib/quality/command_output_processor.rb
quality-37.0.1 lib/quality/command_output_processor.rb
quality-37.0.0 lib/quality/command_output_processor.rb
quality-36.1.0 lib/quality/command_output_processor.rb
quality-36.0.0 lib/quality/command_output_processor.rb
quality-35.2.1 lib/quality/command_output_processor.rb
quality-35.2.0 lib/quality/command_output_processor.rb
quality-35.1.1 lib/quality/command_output_processor.rb
quality-35.0.1 lib/quality/command_output_processor.rb
quality-35.0.0 lib/quality/command_output_processor.rb
quality-34.0.2 lib/quality/command_output_processor.rb
quality-34.0.1 lib/quality/command_output_processor.rb
quality-34.0.0 lib/quality/command_output_processor.rb
quality-33.0.0 lib/quality/command_output_processor.rb
quality-32.1.1 lib/quality/command_output_processor.rb
quality-32.1.0 lib/quality/command_output_processor.rb
quality-32.0.0 lib/quality/command_output_processor.rb
quality-31.3.0 lib/quality/command_output_processor.rb
quality-31.2.1 lib/quality/command_output_processor.rb