Class: EagerEye::Issue

Inherits:
Object
  • Object
show all
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

Class Method Summary collapse

Instance Method Summary collapse

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 = message
  @severity = validate_severity(severity)
  @suggestion = suggestion
end

Instance Attribute Details

#detectorObject (readonly)

Returns the value of attribute detector.



5
6
7
# File 'lib/eager_eye/issue.rb', line 5

def detector
  @detector
end

#file_pathObject (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_numberObject (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

#messageObject (readonly)

Returns the value of attribute message.



5
6
7
# File 'lib/eager_eye/issue.rb', line 5

def message
  @message
end

#severityObject (readonly)

Returns the value of attribute severity.



5
6
7
# File 'lib/eager_eye/issue.rb', line 5

def severity
  @severity
end

#suggestionObject (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

#hashObject



60
61
62
# File 'lib/eager_eye/issue.rb', line 60

def hash
  to_h.hash
end

#meets_minimum_severity?(min_severity) ⇒ Boolean

Returns:

  • (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_levelObject



31
32
33
# File 'lib/eager_eye/issue.rb', line 31

def severity_level
  SEVERITY_ORDER[severity]
end

#to_hObject



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