Class: Uniword::Validation::Rules::ImagesRule

Inherits:
Base
  • Object
show all
Defined in:
lib/uniword/validation/rules/images_rule.rb

Overview

Validates image/media references.

DOC-050: Image relationship targets exist in word/media/ DOC-051: Image content types match file extensions DOC-052: blip embed references resolve to image parts

Constant Summary collapse

R_NS =
"http://schemas.openxmlformats.org/officeDocument/2006/relationships"
A_NS =
"http://schemas.openxmlformats.org/drawingml/2006/main"
IMAGE_TYPES =
%w[
  image/png image/jpeg image/gif image/tiff
  image/bmp image/svg+xml image/emf image/wmf
].freeze

Instance Method Summary collapse

Methods inherited from Base

#context_type, #description, #validity_rule

Instance Method Details

#applicable?(context) ⇒ Boolean

Returns:

  • (Boolean)


24
25
26
# File 'lib/uniword/validation/rules/images_rule.rb', line 24

def applicable?(context)
  context.part_exists?("word/document.xml")
end

#categoryObject



21
# File 'lib/uniword/validation/rules/images_rule.rb', line 21

def category = :images

#check(context) ⇒ Object



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
55
56
57
58
# File 'lib/uniword/validation/rules/images_rule.rb', line 28

def check(context)
  issues = []
  rels = context.relationships
  rels_by_id = rels.to_h { |r| [r[:id], r] }

  # DOC-050: Image relationship targets
  image_rels = rels.select { |r| r[:type]&.include?("image") }
  image_rels.each do |rel|
    target = rel[:target]
    next unless target

    target_path = target.start_with?("/") ? target[1..] : "word/#{target}"

    next if context.part_exists?(target_path)

    issues << issue(
      "Image target '#{target_path}' not found in package",
      part: "word/_rels/document.xml.rels",
      suggestion: "Add the image file '#{target_path}' to the " \
                  "package, or remove the relationship.",
    )
  end

  # DOC-051: Content type consistency
  check_image_content_types(context, image_rels, issues)

  # DOC-052: blip embed references
  check_blip_refs(context, rels_by_id, issues)

  issues
end

#codeObject



20
# File 'lib/uniword/validation/rules/images_rule.rb', line 20

def code = "DOC-050"

#severityObject



22
# File 'lib/uniword/validation/rules/images_rule.rb', line 22

def severity = "error"