Class: Dcc::Validate::Schematron::Rules::IdRefIdLinking

Inherits:
Base show all
Defined in:
lib/dcc/validate/schematron/rules/id_refid_linking.rb

Overview

Validates that every @id on a DCC element has a matching @refId reference and vice versa.

Instance Method Summary collapse

Methods inherited from Dcc::Validate::Schematron::Rule

#code, #severity

Instance Method Details

#check_on(dcc) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/dcc/validate/schematron/rules/id_refid_linking.rb', line 11

def check_on(dcc)
  issues = []
  ids = ::Set.new
  ref_ids = ::Set.new

  collect(dcc, ids, ref_ids)

  unused_ids = ids - ref_ids
  unused_ids.each do |id|
    issues << issue(
      severity: :warning,
      message: "@id '#{id}' is never referenced by any @refId",
    )
  end

  dangling = ref_ids - ids
  dangling.each do |rid|
    issues << issue(
      severity: :error,
      message: "@refId '#{rid}' does not match any @id",
    )
  end

  issues
end