Class: Glossarist::Validation::Rules::LanguageListRule

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

Instance Method Summary collapse

Methods inherited from Base

inherited

Instance Method Details

#applicable?(context) ⇒ Boolean

Returns:

  • (Boolean)


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

def applicable?(context)
  declared = context.declared_languages
  declared.is_a?(Array) && declared.any?
end

#categoryObject



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

def category = :integrity

#check(context) ⇒ Object



17
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/language_list_rule.rb', line 17

def check(context)
  declared = Set.new(context.declared_languages)
  actual = Set.new(context.actual_languages)
  issues = []

  missing = declared - actual
  if missing.any?
    issues << issue(
      "declared languages not found in concepts: #{missing.sort.join(', ')}",
      code: code, severity: severity,
      suggestion: "Update the languages list or add missing localizations",
    )
  end

  extra = actual - declared
  if extra.any?
    issues << issue(
      "concepts use languages not declared: #{extra.sort.join(', ')}",
      code: code, severity: severity,
      suggestion: "Add these languages to the languages list in metadata",
    )
  end

  issues
end

#codeObject



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

def code = "GLS-012"

#scopeObject



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

def scope = :collection

#severityObject



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

def severity = "warning"