Class: Glossarist::Validation::Rules::CitationCompletenessRule

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

Instance Method Summary collapse

Instance Method Details

#applicable?(context) ⇒ Boolean

Returns:

  • (Boolean)


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

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

#categoryObject



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

def category = :quality

#check(context) ⇒ Object



16
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
42
43
44
45
# File 'lib/glossarist/validation/rules/citation_completeness_rule.rb', line 16

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

  gather_all_sources(concept).each_with_index do |source, idx|
    origin = source.origin
    next unless origin

    if origin.text.nil? && origin.source.nil? && origin.id.nil?
      issues << issue(
        "source #{idx + 1} has empty origin (no text, source, or id)",
        code: "GLS-304", severity: severity,
        location: fname,
        suggestion: "Add at minimum an origin.text or origin.source + origin.id",
      )
    end

    next unless origin.structured? && origin.source.nil?

    issues << issue(
      "source #{idx + 1} is structured but missing source field",
      code: "GLS-304", severity: severity,
      location: fname,
      suggestion: "Add origin.source to the citation",
    )
  end

  issues
end

#codeObject



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

def code = "GLS-304"

#scopeObject



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

def scope = :concept

#severityObject



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

def severity = "warning"