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 |
# 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.
71 72 73 |
# File 'lib/rubocop/cop/severity.rb', line 71 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.
57 58 59 60 61 62 63 |
# File 'lib/rubocop/cop/severity.rb', line 57 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.
47 48 49 |
# File 'lib/rubocop/cop/severity.rb', line 47 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.
66 67 68 |
# File 'lib/rubocop/cop/severity.rb', line 66 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.
52 53 54 |
# File 'lib/rubocop/cop/severity.rb', line 52 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.
42 43 44 |
# File 'lib/rubocop/cop/severity.rb', line 42 def to_s @name.to_s end |