Class: Glossarist::Validation::Rules::TermsPresenceRule

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

Instance Method Summary collapse

Methods inherited from Base

inherited

Instance Method Details

#applicable?(context) ⇒ Boolean

Returns:

  • (Boolean)


12
13
14
# File 'lib/glossarist/validation/rules/terms_presence_rule.rb', line 12

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

#categoryObject



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

def category = :structure

#check(context) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/glossarist/validation/rules/terms_presence_rule.rb', line 16

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 || []
    next unless terms.empty?

    issues << issue(
      "#{fname}/#{lang}: must have at least 1 term",
      code: code, severity: severity,
      location: "#{fname}/#{lang}",
      suggestion: "Add at least one term/designation to this localization",
    )
  end

  issues
end

#codeObject



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

def code = "GLS-005"

#scopeObject



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

def scope = :concept

#severityObject



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

def severity = "error"