Class: QuietQuality::Message

Inherits:
Object
  • Object
show all
Defined in:
lib/quiet_quality/message.rb

Constant Summary collapse

REQUIRED_ATTRS =
%w[path body start_line tool_name].freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(**attrs) ⇒ Message

Returns a new instance of Message.



11
12
13
14
# File 'lib/quiet_quality/message.rb', line 11

def initialize(**attrs)
  @attrs = attrs.map { |k, v| [k.to_s, v] }.to_h
  validate_attrs!
end

Instance Attribute Details

#annotated_lineObject



40
41
42
# File 'lib/quiet_quality/message.rb', line 40

def annotated_line
  @annotated_line ||= @attrs.fetch("annotated_line", nil)
end

Class Method Details

.load(hash) ⇒ Object



7
8
9
# File 'lib/quiet_quality/message.rb', line 7

def self.load(hash)
  new(**hash)
end

Instance Method Details

#bodyObject



24
25
26
# File 'lib/quiet_quality/message.rb', line 24

def body
  @_body ||= @attrs.fetch("body")
end

#levelObject



44
45
46
# File 'lib/quiet_quality/message.rb', line 44

def level
  @_level ||= @attrs.fetch("level", nil)
end

#pathObject



20
21
22
# File 'lib/quiet_quality/message.rb', line 20

def path
  @_path ||= @attrs.fetch("path")
end

#ruleObject



48
49
50
# File 'lib/quiet_quality/message.rb', line 48

def rule
  @_rule ||= @attrs.fetch("rule", nil)
end

#start_lineObject



32
33
34
# File 'lib/quiet_quality/message.rb', line 32

def start_line
  @_start_line ||= @attrs.fetch("start_line")
end

#stop_lineObject



36
37
38
# File 'lib/quiet_quality/message.rb', line 36

def stop_line
  @_stop_line ||= @attrs.fetch("stop_line", start_line)
end

#to_hObject



16
17
18
# File 'lib/quiet_quality/message.rb', line 16

def to_h
  @attrs.map { |k, v| [k.to_s, v] }.to_h
end

#tool_nameObject



28
29
30
# File 'lib/quiet_quality/message.rb', line 28

def tool_name
  @_tool_name ||= @attrs.fetch("tool_name")
end