Sha256: 03bfa4192736f994e83c54066f77d56164f34363e48dc823fd33e5ed402fe6d8

Contents?: true

Size: 1.06 KB

Versions: 6

Compression:

Stored size: 1.06 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 = begin
      `cane`
    rescue Errno::ENOENT
      "Cane not found"
    end
    { :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 = :red
      color = :yellow if @violations.between?(1, 9)
      @violations = @violations.to_s.send color
    end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
rake_check-0.1.8 lib/rake_check/cane_checker.rb
rake_check-0.1.7 lib/rake_check/cane_checker.rb
rake_check-0.1.6 lib/rake_check/cane_checker.rb
rake_check-0.1.5 lib/rake_check/cane_checker.rb
rake_check-0.1.4 lib/rake_check/cane_checker.rb
rake_check-0.1.3 lib/rake_check/cane_checker.rb