Class: Glossarist::Validation::Rules::DesignationTypeRule

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

Constant Summary collapse

VALID_TYPES =
Designation::SERIALIZED_TYPES.values.grep(String).uniq.freeze

Instance Method Summary collapse

Methods inherited from Base

inherited

Instance Method Details

#applicable?(context) ⇒ Boolean

Returns:

  • (Boolean)


14
15
16
# File 'lib/glossarist/validation/rules/designation_type_rule.rb', line 14

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

#categoryObject



8
# File 'lib/glossarist/validation/rules/designation_type_rule.rb', line 8

def category = :schema

#check(context) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/glossarist/validation/rules/designation_type_rule.rb', line 18

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

  concept.localizations.each do |l10n|
    lang = l10n.language_code || "unknown"
    terms = l10n.data&.terms || []
    terms.each_with_index do |term, idx|
      type = designation_type(term)
      next unless type

      unless VALID_TYPES.include?(type)
        issues << issue(
          "#{lang}: term #{idx + 1} has unknown designation type '#{type}'",
          location: fname,
          suggestion: "Use one of: #{VALID_TYPES.join(', ')}",
        )
      end
    end
  end

  issues
end

#codeObject



7
# File 'lib/glossarist/validation/rules/designation_type_rule.rb', line 7

def code = "GLS-207"

#scopeObject



10
# File 'lib/glossarist/validation/rules/designation_type_rule.rb', line 10

def scope = :concept

#severityObject



9
# File 'lib/glossarist/validation/rules/designation_type_rule.rb', line 9

def severity = "error"