Class: RuboCop::Cop::Severity
- Inherits:
-
Object
- Object
- RuboCop::Cop::Severity
- Includes:
- Comparable
- Defined in:
- lib/rubocop/cop/severity.rb
Overview
Severity class is simple value object about severity
Constant Summary collapse
- NAMES =
%i[info refactor convention warning error fatal].freeze
- CODE_TABLE =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
{ I: :info, R: :refactor, C: :convention, W: :warning, E: :error, F: :fatal }.freeze
Instance Attribute Summary collapse
-
#name ⇒ Symbol
readonly
Severity.
Class Method Summary collapse
Instance Method Summary collapse
- #<=>(other) ⇒ Object
- #==(other) ⇒ Object
- #code ⇒ Object
- #hash ⇒ Object
-
#initialize(name_or_code) ⇒ Severity
constructor
private
A new instance of Severity.
- #level ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(name_or_code) ⇒ Severity
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns a new instance of Severity.
30 31 32 33 34 35 36 |
# File 'lib/rubocop/cop/severity.rb', line 30 def initialize(name_or_code) name = Severity.name_from_code(name_or_code) raise ArgumentError, "Unknown severity: #{name}" unless NAMES.include?(name) @name = name.freeze freeze end |
Instance Attribute Details
#name ⇒ Symbol (readonly)
Returns severity. any of ‘:info`, `:refactor`, `:convention`, `:warning`, `:error` or `:fatal`.
22 23 24 |
# File 'lib/rubocop/cop/severity.rb', line 22 def name @name end |
Class Method Details
.name_from_code(code) ⇒ Object
24 25 26 27 |
# File 'lib/rubocop/cop/severity.rb', line 24 def self.name_from_code(code) name = code.to_sym CODE_TABLE[name] || name end |
Instance Method Details
#<=>(other) ⇒ Object
62 63 64 |
# File 'lib/rubocop/cop/severity.rb', line 62 def <=>(other) level <=> other.level end |
#==(other) ⇒ Object
50 51 52 53 54 55 56 |
# File 'lib/rubocop/cop/severity.rb', line 50 def ==(other) @name == if other.is_a?(Symbol) other else other.name end end |
#code ⇒ Object
42 43 44 |
# File 'lib/rubocop/cop/severity.rb', line 42 def code @name.to_s[0].upcase end |
#hash ⇒ Object
58 59 60 |
# File 'lib/rubocop/cop/severity.rb', line 58 def hash @name.hash end |
#level ⇒ Object
46 47 48 |
# File 'lib/rubocop/cop/severity.rb', line 46 def level NAMES.index(name) + 1 end |
#to_s ⇒ Object
38 39 40 |
# File 'lib/rubocop/cop/severity.rb', line 38 def to_s @name.to_s end |