Class: EagerEye::Issue
- Inherits:
-
Object
- Object
- EagerEye::Issue
- Defined in:
- lib/eager_eye/issue.rb
Constant Summary collapse
- VALID_SEVERITIES =
%i[info warning error].freeze
- SEVERITY_ORDER =
{ info: 0, warning: 1, error: 2 }.freeze
Instance Attribute Summary collapse
-
#detector ⇒ Object
readonly
Returns the value of attribute detector.
-
#file_path ⇒ Object
readonly
Returns the value of attribute file_path.
-
#line_number ⇒ Object
readonly
Returns the value of attribute line_number.
-
#message ⇒ Object
readonly
Returns the value of attribute message.
-
#severity ⇒ Object
readonly
Returns the value of attribute severity.
-
#suggestion ⇒ Object
readonly
Returns the value of attribute suggestion.
Class Method Summary collapse
Instance Method Summary collapse
- #==(other) ⇒ Object (also: #eql?)
- #hash ⇒ Object
-
#initialize(detector:, file_path:, line_number:, message:, severity: :warning, suggestion: nil) ⇒ Issue
constructor
A new instance of Issue.
- #meets_minimum_severity?(min_severity) ⇒ Boolean
- #severity_level ⇒ Object
- #to_h ⇒ Object
- #to_json(*args) ⇒ Object
Constructor Details
#initialize(detector:, file_path:, line_number:, message:, severity: :warning, suggestion: nil) ⇒ Issue
Returns a new instance of Issue.
10 11 12 13 14 15 16 17 |
# File 'lib/eager_eye/issue.rb', line 10 def initialize(detector:, file_path:, line_number:, message:, severity: :warning, suggestion: nil) @detector = detector @file_path = file_path @line_number = line_number @message = @severity = validate_severity(severity) @suggestion = suggestion end |
Instance Attribute Details
#detector ⇒ Object (readonly)
Returns the value of attribute detector.
5 6 7 |
# File 'lib/eager_eye/issue.rb', line 5 def detector @detector end |
#file_path ⇒ Object (readonly)
Returns the value of attribute file_path.
5 6 7 |
# File 'lib/eager_eye/issue.rb', line 5 def file_path @file_path end |
#line_number ⇒ Object (readonly)
Returns the value of attribute line_number.
5 6 7 |
# File 'lib/eager_eye/issue.rb', line 5 def line_number @line_number end |
#message ⇒ Object (readonly)
Returns the value of attribute message.
5 6 7 |
# File 'lib/eager_eye/issue.rb', line 5 def @message end |
#severity ⇒ Object (readonly)
Returns the value of attribute severity.
5 6 7 |
# File 'lib/eager_eye/issue.rb', line 5 def severity @severity end |
#suggestion ⇒ Object (readonly)
Returns the value of attribute suggestion.
5 6 7 |
# File 'lib/eager_eye/issue.rb', line 5 def suggestion @suggestion end |
Class Method Details
.from_h(hash) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/eager_eye/issue.rb', line 19 def self.from_h(hash) h = hash.transform_keys(&:to_sym) new( detector: h.fetch(:detector).to_sym, file_path: h.fetch(:file_path), line_number: h.fetch(:line_number), message: h.fetch(:message), severity: (h[:severity] || :warning).to_sym, suggestion: h[:suggestion] ) end |
Instance Method Details
#==(other) ⇒ Object Also known as: eql?
54 55 56 |
# File 'lib/eager_eye/issue.rb', line 54 def ==(other) other.is_a?(Issue) && to_h == other.to_h end |
#hash ⇒ Object
60 61 62 |
# File 'lib/eager_eye/issue.rb', line 60 def hash to_h.hash end |
#meets_minimum_severity?(min_severity) ⇒ Boolean
35 36 37 |
# File 'lib/eager_eye/issue.rb', line 35 def meets_minimum_severity?(min_severity) severity_level >= SEVERITY_ORDER.fetch(min_severity, 0) end |
#severity_level ⇒ Object
31 32 33 |
# File 'lib/eager_eye/issue.rb', line 31 def severity_level SEVERITY_ORDER[severity] end |
#to_h ⇒ Object
39 40 41 42 43 44 45 46 47 48 |
# File 'lib/eager_eye/issue.rb', line 39 def to_h { detector:, file_path:, line_number:, message:, severity:, suggestion: } end |
#to_json(*args) ⇒ Object
50 51 52 |
# File 'lib/eager_eye/issue.rb', line 50 def to_json(*args) to_h.to_json(*args) end |