Class: Uniword::Validation::Rules::HeadersFootersRule

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

Overview

Validates header and footer references.

DOC-030: headerReference/footerReference targets exist in ZIP DOC-031: headerReference/footerReference type is valid

Constant Summary collapse

W_NS =
"http://schemas.openxmlformats.org/wordprocessingml/2006/main"
R_NS =
"http://schemas.openxmlformats.org/officeDocument/2006/relationships"
VALID_TYPES =
%w[default first even].freeze

Instance Method Summary collapse

Methods inherited from Base

#description, #validity_rule

Instance Method Details

#applicable?(context) ⇒ Boolean

Returns:

  • (Boolean)


22
23
24
# File 'lib/uniword/validation/rules/headers_footers_rule.rb', line 22

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

#categoryObject



19
# File 'lib/uniword/validation/rules/headers_footers_rule.rb', line 19

def category = :headers_footers

#check(context) ⇒ Object



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/uniword/validation/rules/headers_footers_rule.rb', line 26

def check(context)
  issues = []
  doc = context.document_xml
  return issues unless doc

  rels = context.relationships
  rels_by_id = rels.to_h { |r| [r[:id], r] }

  # Check header references
  doc.root.xpath(".//w:headerReference", "w" => W_NS).each do |ref|
    check_reference(ref, "header", rels_by_id, context, issues)
  end

  # Check footer references
  doc.root.xpath(".//w:footerReference", "w" => W_NS).each do |ref|
    check_reference(ref, "footer", rels_by_id, context, issues)
  end

  issues
end

#codeObject



18
# File 'lib/uniword/validation/rules/headers_footers_rule.rb', line 18

def code = "DOC-030"

#severityObject



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

def severity = "error"