Class: Glossarist::Validation::Rules::RelatedConceptTargetRule

Inherits:
Base
  • Object
show all
Defined in:
lib/glossarist/validation/rules/related_concept_target_rule.rb

Overview

Verifies that related concept refs point to concepts that exist in the dataset (for local refs) or have valid source/URN (for external).

Constant Summary collapse

URN_RE =
%r{\Aurn:[a-z0-9][a-z0-9-]{0,31}:[a-z0-9()+,\-.:=@;$_!*'%/?#]+\z}i.freeze

Instance Method Summary collapse

Methods inherited from Base

inherited

Instance Method Details

#applicable?(context) ⇒ Boolean

Returns:

  • (Boolean)


16
17
18
# File 'lib/glossarist/validation/rules/related_concept_target_rule.rb', line 16

def applicable?(context)
  context.concept.related&.any?
end

#categoryObject



12
# File 'lib/glossarist/validation/rules/related_concept_target_rule.rb', line 12

def category = :references

#check(context) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/glossarist/validation/rules/related_concept_target_rule.rb', line 20

def check(context)
  concept = context.concept
  fname = context.file_name
  issues = []

  (concept.related || []).each_with_index do |rel, idx|
    ref = rel.ref
    next unless ref

    id = ref.id
    source = ref.source

    if id && local_ref?(source)
      # Local ref — concept_id must exist in dataset
      unless context.concept_ids.include?(id)
        issues << issue(
          "related concept #{idx + 1} references '#{id}' which is not in the dataset",
          location: fname,
          suggestion: "Add concept '#{id}' to the dataset or fix the reference",
        )
      end
    elsif source && !id
      # Source-only ref — should be a valid URN or known format
      if source.start_with?("urn:") && !URN_RE.match?(source)
        issues << issue(
          "related concept #{idx + 1} has invalid URN '#{source}'",
          location: fname,
          suggestion: "Fix the URN format (e.g. urn:iso:std:iso:ts:14812)",
        )
      end
    end
  end

  issues
end

#codeObject



11
# File 'lib/glossarist/validation/rules/related_concept_target_rule.rb', line 11

def code = "GLS-110"

#scopeObject



14
# File 'lib/glossarist/validation/rules/related_concept_target_rule.rb', line 14

def scope = :concept

#severityObject



13
# File 'lib/glossarist/validation/rules/related_concept_target_rule.rb', line 13

def severity = "warning"