Class: HamlLint::Severity
- Inherits:
-
SimpleDelegator
- Object
- SimpleDelegator
- HamlLint::Severity
- Includes:
- Comparable
- Defined in:
- lib/haml_lint/severity.rb
Overview
Models the severity of a lint
Constant Summary collapse
- SEVERITY_ERROR =
:error
- SEVERITY_WARNING =
:warning
- COLORS =
{ error: :red, warning: :yellow }.freeze
- MARKS =
{ error: 'E', warning: 'W' }.freeze
- NAMES =
[SEVERITY_WARNING, SEVERITY_ERROR].freeze
Instance Method Summary collapse
-
#<=>(other) ⇒ Integer
Compares the severity to another severity or a symbol.
-
#color ⇒ Symbol
The color of the mark in reporters.
-
#error? ⇒ Boolean
Checks whether the severity is an error.
-
#initialize(name) ⇒ Severity
constructor
Creates a new severity for a lint.
-
#level ⇒ Integer
The level of severity for the lint.
-
#mark ⇒ Object
The symbol to use in a Reporter::ProgressReporter.
-
#mark_with_color ⇒ Object
The colorized symbol to use in a reporter.
-
#name ⇒ Object
The name of the severity.
-
#warning? ⇒ Boolean
Checks whether the severity is a warning.
Constructor Details
#initialize(name) ⇒ Severity
Creates a new severity for a lint
24 25 26 27 28 29 |
# File 'lib/haml_lint/severity.rb', line 24 def initialize(name) name = name.name if name.is_a?(Severity) name ||= :warning fail Exceptions::UnknownSeverity, "Unknown severity: #{name}" unless NAMES.include?(name) super end |
Instance Method Details
#<=>(other) ⇒ Integer
Compares the severity to another severity or a symbol
92 93 94 95 |
# File 'lib/haml_lint/severity.rb', line 92 def <=>(other) other = Severity.new(other) unless other.respond_to?(:level) level <=> other.level end |
#color ⇒ Symbol
The color of the mark in reporters.
34 35 36 |
# File 'lib/haml_lint/severity.rb', line 34 def color COLORS[__getobj__] end |
#error? ⇒ Boolean
Checks whether the severity is an error
45 46 47 |
# File 'lib/haml_lint/severity.rb', line 45 def error? __getobj__ == :error end |
#level ⇒ Integer
The level of severity for the lint
53 54 55 |
# File 'lib/haml_lint/severity.rb', line 53 def level NAMES.index(__getobj__) + 1 end |
#mark ⇒ Object
The symbol to use in a Reporter::ProgressReporter.
60 61 62 |
# File 'lib/haml_lint/severity.rb', line 60 def mark MARKS[__getobj__] end |
#mark_with_color ⇒ Object
The colorized symbol to use in a reporter.
67 68 69 |
# File 'lib/haml_lint/severity.rb', line 67 def mark_with_color Rainbow.global.wrap(mark).public_send(color) end |
#name ⇒ Object
The name of the severity.
74 75 76 |
# File 'lib/haml_lint/severity.rb', line 74 def name __getobj__ end |
#warning? ⇒ Boolean
Checks whether the severity is a warning
85 86 87 |
# File 'lib/haml_lint/severity.rb', line 85 def warning? __getobj__ == :warning end |