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 =
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[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.
{ R: :refactor, C: :convention, W: :warning, E: :error, F: :fatal }.freeze
Instance Attribute Summary collapse
-
#name ⇒ Symbol
readonly
Severity.
Class Method Summary collapse
- .name_from_code(code) ⇒ Object private
Instance Method Summary collapse
- #<=>(other) ⇒ Object private
- #==(other) ⇒ Object private
- #code ⇒ Object private
- #hash ⇒ Object private
-
#initialize(name_or_code) ⇒ Severity
constructor
private
A new instance of Severity.
- #level ⇒ Object private
- #to_s ⇒ Object private
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.
32 33 34 35 36 37 38 39 40 |
# File 'lib/rubocop/cop/severity.rb', line 32 def initialize(name_or_code) name = Severity.name_from_code(name_or_code) unless NAMES.include?(name) raise ArgumentError, "Unknown severity: #{name}" end @name = name.freeze freeze end |
Instance Attribute Details
#name ⇒ Symbol (readonly)
Returns severity. any of ‘:refactor`, `:convention`, `:warning`, `:error` or `:fatal`.
23 24 25 |
# File 'lib/rubocop/cop/severity.rb', line 23 def name @name end |
Class Method Details
.name_from_code(code) ⇒ Object
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.
26 27 28 29 |
# File 'lib/rubocop/cop/severity.rb', line 26 def self.name_from_code(code) name = code.to_sym CODE_TABLE[name] || name end |
Instance Method Details
#<=>(other) ⇒ Object
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.
72 73 74 |
# File 'lib/rubocop/cop/severity.rb', line 72 def <=>(other) level <=> other.level end |
#==(other) ⇒ Object
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.
58 59 60 61 62 63 64 |
# File 'lib/rubocop/cop/severity.rb', line 58 def ==(other) @name == if other.is_a?(Symbol) other else other.name end end |
#code ⇒ Object
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.
48 49 50 |
# File 'lib/rubocop/cop/severity.rb', line 48 def code @name.to_s[0].upcase end |
#hash ⇒ Object
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.
67 68 69 |
# File 'lib/rubocop/cop/severity.rb', line 67 def hash @name.hash end |
#level ⇒ Object
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.
53 54 55 |
# File 'lib/rubocop/cop/severity.rb', line 53 def level NAMES.index(name) + 1 end |
#to_s ⇒ Object
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.
43 44 45 |
# File 'lib/rubocop/cop/severity.rb', line 43 def to_s @name.to_s end |