Class: Glossarist::Validation::Rules::RelatedConceptSymmetryRule
- Defined in:
- lib/glossarist/validation/rules/related_concept_symmetry_rule.rb
Constant Summary collapse
- INVERSE =
{ "supersedes" => "superseded_by", "superseded_by" => "supersedes", "narrower" => "broader", "broader" => "narrower", "deprecates" => "deprecated_by", "deprecated_by" => "deprecates", }.freeze
- DIRECTIONAL =
%w[supersedes deprecates narrower].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
23 24 25 |
# File 'lib/glossarist/validation/rules/related_concept_symmetry_rule.rb', line 23 def applicable?(context) context.concepts.any? { |c| c.&.any? } end |
#category ⇒ Object
8 |
# File 'lib/glossarist/validation/rules/related_concept_symmetry_rule.rb', line 8 def category = :references |
#check(context) ⇒ Object
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_symmetry_rule.rb', line 27 def check(context) index = build_relation_index(context.concepts) issues = [] context.concepts.each do |concept| next unless concept.&.any? concept_id = concept.data&.id&.to_s || "unknown" (concept. || []).each do |rel| inverse = INVERSE[rel.type] next unless inverse target_id = resolve_target_id(rel) next unless target_id targets = index[target_id] next if targets && targets.any? { |r| r.type == inverse } issues << issue( "#{concept_id}: #{rel.type} #{target_id} but #{target_id} has no #{inverse} back-link", location: concept_id, suggestion: "Add a #{inverse} relation on #{target_id} pointing back to #{concept_id}", ) end end issues end |
#code ⇒ Object
7 |
# File 'lib/glossarist/validation/rules/related_concept_symmetry_rule.rb', line 7 def code = "GLS-112" |
#scope ⇒ Object
10 |
# File 'lib/glossarist/validation/rules/related_concept_symmetry_rule.rb', line 10 def scope = :collection |
#severity ⇒ Object
9 |
# File 'lib/glossarist/validation/rules/related_concept_symmetry_rule.rb', line 9 def severity = "warning" |