Sha256: b57ca43b47b5f18be1be164b4b1071c8718e50e83a58fba7ebe0281b92b4e03f

Contents?: true

Size: 1.01 KB

Versions: 4

Compression:

Stored size: 1.01 KB

Contents

require 'colored'
##
# CaneChecker checks the output code smells with cane
#
# @author dmasur
class CaneChecker
  ##
  # Gives the Checkresult
  #
  # @return [Hash] Checkresult
  # @author dmasur
  def result
    @shell_output = `cane`
    { :type => :cane, :check_output => @shell_output, :status => status }
  end

  private
    ##
    # Gives the Check Status
    #
    # @return [String] Checkstatus
    # @author dmasur
    def status
      @violations = @shell_output.scan(/\((\d*)\):/).flatten.map(&:to_i).
        inject(0){ |sum, value| sum += value }
      if @violations > 0
        color_violations
        "#{@violations} Style Violations"
      elsif @shell_output.empty?
        'OK'.green
      else
        'N/A'
      end
    end

    ##
    # Color Code Validation Count
    #
    # @return [String] Colored Validation Count
    # @author dmasur
    def color_violations
      color = case @violations
      when 1..9 then :yellow
      else :red
      end
      @violations = @violations.to_s.send color
    end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
rake_check-0.1.2 lib/rake_check/cane_checker.rb
rake_check-0.1.1 lib/rake_check/cane_checker.rb
rake_check-0.1.0 lib/rake_check/cane_checker.rb
rake_check-0.0.1 lib/rake_check/cane_checker.rb