Class: Glossarist::Validation::Rules::SourceUrnFormatRule

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

Overview

Validates that every URN-format source in citations and references follows a recognized scheme (iso, iec, itu, etc).

Constant Summary collapse

URN_RE =
%r{\Aurn:([a-z0-9][a-z0-9-]{0,31}):(.+)\z}i.freeze
KNOWN_SCHEMES =
%w[
  iso iec itu iso:std:iso iso:std:iec
].freeze

Instance Method Summary collapse

Methods inherited from Base

inherited

Instance Method Details

#applicable?(context) ⇒ Boolean

Returns:

  • (Boolean)


20
21
22
# File 'lib/glossarist/validation/rules/source_urn_format_rule.rb', line 20

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

#categoryObject



16
# File 'lib/glossarist/validation/rules/source_urn_format_rule.rb', line 16

def category = :quality

#check(context) ⇒ Object



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/glossarist/validation/rules/source_urn_format_rule.rb', line 24

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

  all_refs(concept).each_with_index do |ref_str, idx|
    next unless ref_str && ref_str.start_with?("urn:")

    match = URN_RE.match(ref_str)
    unless match
      issues << issue(
        "source #{idx + 1} has malformed URN '#{ref_str}'",
        location: fname,
        suggestion: "Fix the URN to follow RFC 8141 format",
      )
    end
  end

  issues
end

#codeObject



15
# File 'lib/glossarist/validation/rules/source_urn_format_rule.rb', line 15

def code = "GLS-310"

#scopeObject



18
# File 'lib/glossarist/validation/rules/source_urn_format_rule.rb', line 18

def scope = :concept

#severityObject



17
# File 'lib/glossarist/validation/rules/source_urn_format_rule.rb', line 17

def severity = "warning"