Class: Dcc::Validate::Issue

Inherits:
Lutaml::Model::Serializable
  • Object
show all
Defined in:
lib/dcc/validate/issue.rb

Overview

A single validation issue (XSD error, Schematron failed assert, or business-rule violation). Carries enough metadata for both human and machine reporting.

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.build(severity:, message:, code: nil, line: nil, column: nil, path: nil, source: nil) ⇒ Object

Convenience constructor used by validators.

Parameters:

  • severity (Symbol, String)

    see Dcc::Validate::Severity.normalize.

  • message (String)

    human-readable description.

  • code (String, nil) (defaults to: nil)

    validator-specific code (e.g. "dcc.date-range").

  • line (Integer, nil) (defaults to: nil)

    XML line number if known.

  • column (Integer, nil) (defaults to: nil)

    XML column number if known.

  • path (String, nil) (defaults to: nil)

    XPath / element path if known.

  • source (String, nil) (defaults to: nil)

    validator name (e.g. "xsd", "schematron").



27
28
29
30
31
32
33
34
35
36
37
# File 'lib/dcc/validate/issue.rb', line 27

def self.build(severity:, message:, code: nil, line: nil, column: nil, path: nil, source: nil)
  new(
    severity: ::Dcc::Validate::Severity.normalize(severity),
    message: message,
    code: code,
    line: line,
    column: column,
    path: path,
    source: source,
  )
end

Instance Method Details

#failing?Boolean

Returns whether this issue fails validation (severity == error).

Returns:

  • (Boolean)

    whether this issue fails validation (severity == error).



40
41
42
# File 'lib/dcc/validate/issue.rb', line 40

def failing?
  severity == ::Dcc::Validate::Severity::ERROR
end

#to_sObject



44
45
46
47
48
49
50
51
52
53
# File 'lib/dcc/validate/issue.rb', line 44

def to_s
  loc = []
  loc << "line #{line}" if line
  loc << "col #{column}" if column
  loc << path if path
  loc_str = loc.empty? ? "" : " [#{loc.join(' ')}]"
  code_str = code ? "(#{code}) " : ""
  src_str = source ? "#{source}: " : ""
  "#{src_str}#{severity.upcase} #{code_str}#{message}#{loc_str}"
end