Class: Glossarist::Validation::Rules::RelatedConceptTargetRule
- 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
- #applicable?(context) ⇒ Boolean
- #category ⇒ Object
- #check(context) ⇒ Object
- #code ⇒ Object
- #scope ⇒ Object
- #severity ⇒ Object
Methods inherited from Base
Instance Method Details
#applicable?(context) ⇒ Boolean
16 17 18 |
# File 'lib/glossarist/validation/rules/related_concept_target_rule.rb', line 16 def applicable?(context) context.concept.&.any? end |
#category ⇒ Object
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. || []).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 |
#code ⇒ Object
11 |
# File 'lib/glossarist/validation/rules/related_concept_target_rule.rb', line 11 def code = "GLS-110" |
#scope ⇒ Object
14 |
# File 'lib/glossarist/validation/rules/related_concept_target_rule.rb', line 14 def scope = :concept |
#severity ⇒ Object
13 |
# File 'lib/glossarist/validation/rules/related_concept_target_rule.rb', line 13 def severity = "warning" |