Sha256: b797a8628cf0d994c752351eac489f5292bb76a68d21dee87405e267d5630ecc

Contents?: true

Size: 1.06 KB

Versions: 12

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

12 entries across 12 versions & 1 rubygems

Version Path
rake_check-0.3.5 lib/rake_check/cane_checker.rb
rake_check-0.3.4 lib/rake_check/cane_checker.rb
rake_check-0.3.3 lib/rake_check/cane_checker.rb
rake_check-0.3.2 lib/rake_check/cane_checker.rb
rake_check-0.3.1 lib/rake_check/cane_checker.rb
rake_check-0.3.0 lib/rake_check/cane_checker.rb
rake_check-0.2.2 lib/rake_check/cane_checker.rb
rake_check-0.2.1 lib/rake_check/cane_checker.rb
rake_check-0.2 lib/rake_check/cane_checker.rb
rake_check-0.1.11 lib/rake_check/cane_checker.rb
rake_check-0.1.10 lib/rake_check/cane_checker.rb
rake_check-0.1.9 lib/rake_check/cane_checker.rb