Class: Uniword::Validation::Rules::RsidRule

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

Overview

Validates that paragraphs have rsid attributes.

DOC-109: Paragraphs should have w:rsidR and w:rsidRDefault Validity rule: R12

Constant Summary collapse

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

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/rsid_rule.rb', line 19

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

#categoryObject



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

def category = :structure

#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
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/uniword/validation/rules/rsid_rule.rb', line 23

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

  paras = doc.root.xpath("//w:body/w:p", "w" => W_NS)
  return issues if paras.empty?

  missing_rsid_r = 0
  missing_rsid_r_default = 0

  paras.each do |para|
    missing_rsid_r += 1 unless para["w:rsidR"]
    missing_rsid_r_default += 1 unless para["w:rsidRDefault"]
  end

  total = paras.size
  if missing_rsid_r == total
    issues << issue(
      "No paragraphs have w:rsidR attribute (#{total} paragraphs)",
      part: "word/document.xml",
      severity: "warning",
      suggestion: "Add rsidR attributes to paragraphs for change tracking.",
    )
  end

  if missing_rsid_r_default == total
    issues << issue(
      "No paragraphs have w:rsidRDefault attribute (#{total} paragraphs)",
      part: "word/document.xml",
      severity: "warning",
      suggestion: "Add rsidRDefault attributes to paragraphs.",
    )
  end

  issues
end

#codeObject



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

def code = "DOC-109"

#descriptionObject



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

def description = "Paragraphs should have rsidR and rsidRDefault attributes"

#severityObject



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

def severity = "warning"

#validity_ruleObject



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

def validity_rule = "R12"