Class: Glossarist::Validation::Rules::ImageReferenceRule

Inherits:
Base
  • Object
show all
Defined in:
lib/glossarist/validation/rules/image_reference_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/image_reference_rule.rb', line 12

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

#categoryObject



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

def category = :references

#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
46
47
48
49
50
51
52
53
54
# File 'lib/glossarist/validation/rules/image_reference_rule.rb', line 16

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

  concept.localizations.each do |l10n|
    lang = l10n.language_code || "unknown"

    l10n.text_content.each do |text|
      next unless text
      extractor.extract_from_text(text).each do |ref|
        next unless ref.is_a?(AssetReference)
        next if context.asset_index.resolve?(ref.path)

        issues << issue(
          "unresolved image reference #{ref.path}",
          code: "GLS-103", severity: severity,
          location: "#{fname}/#{lang}",
          suggestion: "add '#{ref.path}' to the dataset's images/ directory",
        )
      end
    end
  end

  asset_refs = extractor.extract_asset_refs_from_concept(concept)
  asset_refs.each do |ref|
    next if context.asset_index.resolve?(ref.path)

    issues << issue(
      "unresolved asset reference #{ref.path}",
      code: "GLS-104", severity: "error",
      location: fname,
      suggestion: "add '#{ref.path}' to the dataset's images/ directory",
    )
  end

  issues
end

#codeObject



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

def code = "GLS-103"

#scopeObject



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

def scope = :concept

#severityObject



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

def severity = "warning"