Sha256: 774f5c792e59109bcc0ecd5a1005429a6325a101518b3fcef8200dcc0440a9f8

Contents?: true

Size: 1.49 KB

Versions: 24

Compression:

Stored size: 1.49 KB

Contents

# encoding: utf-8

module RuboCop
  module Cop
    # Severity class is simple value object about severity
    class Severity
      include Comparable

      # @api private
      NAMES = [:refactor, :convention, :warning, :error, :fatal]

      # @api private
      CODE_TABLE = { R: :refactor, C: :convention,
                     W: :warning, E: :error, F: :fatal }

      # @api public
      #
      # @!attribute [r] name
      #
      # @return [Symbol]
      #   severity.
      #   any of `:refactor`, `:convention`, `:warning`, `:error` or `:fatal`.
      attr_reader :name

      # @api private
      def self.name_from_code(code)
        name = code.to_sym
        CODE_TABLE[name] || name
      end

      # @api private
      def initialize(name_or_code)
        name = Severity.name_from_code(name_or_code)
        unless NAMES.include?(name)
          fail ArgumentError, "Unknown severity: #{name}"
        end
        @name = name.freeze
        freeze
      end

      # @api private
      def to_s
        @name.to_s
      end

      # @api private
      def code
        @name.to_s[0].upcase
      end

      # @api private
      def level
        NAMES.index(name) + 1
      end

      # @api private
      def ==(other)
        if other.is_a?(Symbol)
          @name == other
        else
          @name == other.name
        end
      end

      # @api private
      def hash
        @name.hash
      end

      # @api private
      def <=>(other)
        level <=> other.level
      end
    end
  end
end

Version data entries

24 entries across 24 versions & 2 rubygems

Version Path
rubyjobbuilderdsl-0.0.2 vendor/bundle/ruby/2.1.0/gems/rubocop-0.26.0/lib/rubocop/cop/severity.rb
rubyjobbuilderdsl-0.0.1 vendor/bundle/ruby/2.1.0/gems/rubocop-0.26.0/lib/rubocop/cop/severity.rb
rubocop-0.35.1 lib/rubocop/cop/severity.rb
rubocop-0.35.0 lib/rubocop/cop/severity.rb
rubocop-0.34.2 lib/rubocop/cop/severity.rb
rubocop-0.34.1 lib/rubocop/cop/severity.rb
rubocop-0.34.0 lib/rubocop/cop/severity.rb
rubocop-0.33.0 lib/rubocop/cop/severity.rb
rubocop-0.32.1 lib/rubocop/cop/severity.rb
rubocop-0.32.0 lib/rubocop/cop/severity.rb
rubocop-0.31.0 lib/rubocop/cop/severity.rb
rubocop-0.30.1 lib/rubocop/cop/severity.rb
rubocop-0.30.0 lib/rubocop/cop/severity.rb
rubocop-0.29.1 lib/rubocop/cop/severity.rb
rubocop-0.29.0 lib/rubocop/cop/severity.rb
rubocop-0.28.0 lib/rubocop/cop/severity.rb
rubocop-0.27.1 lib/rubocop/cop/severity.rb
rubocop-0.27.0 lib/rubocop/cop/severity.rb
rubocop-0.26.1 lib/rubocop/cop/severity.rb
rubocop-0.26.0 lib/rubocop/cop/severity.rb