Class: Uniword::Validation::Rules::FootnotesRule

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

Overview

Validates footnotes and endnotes consistency.

DOC-020: footnotePr/endnotePr implies footnotes.xml/endnotes.xml exists DOC-021: footnoteReference/endnoteReference IDs exist in parts DOC-022: Separator entries present when footnotePr defined

Constant Summary collapse

W_NS =
"http://schemas.openxmlformats.org/wordprocessingml/2006/main"

Instance Method Summary collapse

Methods inherited from Base

#description, #validity_rule

Instance Method Details

#applicable?(context) ⇒ Boolean

Returns:

  • (Boolean)


20
21
22
# File 'lib/uniword/validation/rules/footnotes_rule.rb', line 20

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

#categoryObject



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

def category = :footnotes

#check(context) ⇒ Object



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
55
56
57
58
59
60
61
62
63
# File 'lib/uniword/validation/rules/footnotes_rule.rb', line 24

def check(context)
  issues = []

  settings = context.settings_xml
  return issues unless settings

  has_footnote_pr = settings.root.xpath(".//w:footnotePr",
                                        "w" => W_NS).any?
  has_endnote_pr = settings.root.xpath(".//w:endnotePr",
                                       "w" => W_NS).any?

  # DOC-020: Check parts exist when properties are declared
  if has_footnote_pr && !context.part_exists?("word/footnotes.xml")
    issues << issue(
      "settings.xml declares footnotePr but word/footnotes.xml is missing",
      part: "word/settings.xml",
      suggestion: "Add a minimal footnotes.xml with separator entries " \
                  "(id=-1, id=0), or remove footnotePr from settings.xml " \
                  "if no footnotes are used.",
    )
  end

  if has_endnote_pr && !context.part_exists?("word/endnotes.xml")
    issues << issue(
      "settings.xml declares endnotePr but word/endnotes.xml is missing",
      part: "word/settings.xml",
      suggestion: "Add a minimal endnotes.xml with separator entries " \
                  "(id=-1, id=0), or remove endnotePr from settings.xml " \
                  "if no endnotes are used.",
    )
  end

  # DOC-022: Check separator entries
  check_separators(context, has_footnote_pr, has_endnote_pr, issues)

  # DOC-021: Check reference IDs
  check_footnote_references(context, issues)

  issues
end

#codeObject



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

def code = "DOC-020"

#severityObject



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

def severity = "error"