Class: Uniword::Validation::Rules::ContentTypesCoverageRule

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

Overview

Validates that every ZIP entry has content type coverage.

DOC-106: All ZIP entries must be covered by Content_Types Validity rule: R7

Constant Summary collapse

CT_NS =
"http://schemas.openxmlformats.org/package/2006/content-types"

Instance Method Summary collapse

Methods inherited from Base

#context_type

Instance Method Details

#applicable?(context) ⇒ Boolean

Returns:

  • (Boolean)


19
20
21
# File 'lib/uniword/validation/rules/content_types_coverage_rule.rb', line 19

def applicable?(context)
  context.part_exists?("[Content_Types].xml")
end

#categoryObject



16
# File 'lib/uniword/validation/rules/content_types_coverage_rule.rb', line 16

def category = :content_types

#check(context) ⇒ Object



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
# File 'lib/uniword/validation/rules/content_types_coverage_rule.rb', line 23

def check(context)
  issues = []

  content_types = context.content_types
  override_parts, default_extensions = content_types.keys.partition do |k|
    k.start_with?("/")
  end

  context.zip_entries.each do |entry|
    next if entry.end_with?("/")
    next if entry.end_with?(".rels")
    next if entry == "[Content_Types].xml"
    next if covered?(entry, default_extensions, override_parts)

    issues << issue(
      "ZIP entry '#{entry}' has no content type coverage " \
      "in [Content_Types].xml",
      part: "[Content_Types].xml",
      suggestion: "Add a <Default Extension=\"#{File.extname(entry).delete_prefix('.')}" \
                  "\" .../> or <Override PartName=\"/#{entry}\" .../> entry.",
    )
  end

  issues
end

#codeObject



13
# File 'lib/uniword/validation/rules/content_types_coverage_rule.rb', line 13

def code = "DOC-106"

#descriptionObject



15
# File 'lib/uniword/validation/rules/content_types_coverage_rule.rb', line 15

def description = "Every ZIP entry must have content type coverage"

#severityObject



17
# File 'lib/uniword/validation/rules/content_types_coverage_rule.rb', line 17

def severity = "error"

#validity_ruleObject



14
# File 'lib/uniword/validation/rules/content_types_coverage_rule.rb', line 14

def validity_rule = "R7"