Class: Slamdown::Diagnostic

Inherits:
Object
  • Object
show all
Defined in:
lib/slamdown/diagnostic.rb

Overview

Describes one construction or conversion observation without exposing mutable internal state.

Constant Summary collapse

SEVERITIES =
[:info, :warning, :error].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(code:, severity:, message:, node_path: nil) ⇒ Diagnostic

Returns a new instance of Diagnostic.

Raises:

  • (ArgumentError)


11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/slamdown/diagnostic.rb', line 11

def initialize(code:, severity:, message:, node_path: nil)
	raise ArgumentError, "diagnostic code must be a Symbol" unless code.is_a?(Symbol)
	raise ArgumentError, "invalid diagnostic severity: #{severity.inspect}" unless SEVERITIES.include?(severity)
	raise ArgumentError, "diagnostic message must be a String" unless message.is_a?(String)
	raise ArgumentError, "diagnostic node_path must contain only non-negative integers" unless valid_node_path?(node_path)

	@code = code
	@severity = severity
	@message = message.dup.freeze
	@node_path = node_path && node_path.dup.freeze
	freeze
end

Instance Attribute Details

#codeObject (readonly)

Returns the value of attribute code.



9
10
11
# File 'lib/slamdown/diagnostic.rb', line 9

def code
  @code
end

#messageObject (readonly)

Returns the value of attribute message.



9
10
11
# File 'lib/slamdown/diagnostic.rb', line 9

def message
  @message
end

#node_pathObject (readonly)

Returns the value of attribute node_path.



9
10
11
# File 'lib/slamdown/diagnostic.rb', line 9

def node_path
  @node_path
end

#severityObject (readonly)

Returns the value of attribute severity.



9
10
11
# File 'lib/slamdown/diagnostic.rb', line 9

def severity
  @severity
end