Class: Uniword::Validation::Rules::RsidRule
- 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
- #applicable?(context) ⇒ Boolean
- #category ⇒ Object
- #check(context) ⇒ Object
- #code ⇒ Object
- #description ⇒ Object
- #severity ⇒ Object
- #validity_rule ⇒ Object
Instance Method Details
#applicable?(context) ⇒ Boolean
21 22 23 |
# File 'lib/uniword/validation/rules/rsid_rule.rb', line 21 def applicable?(context) context.part_exists?("word/document.xml") end |
#category ⇒ Object
18 |
# File 'lib/uniword/validation/rules/rsid_rule.rb', line 18 def category = :structure |
#check(context) ⇒ Object
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 |
# File 'lib/uniword/validation/rules/rsid_rule.rb', line 25 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 |
#code ⇒ Object
15 |
# File 'lib/uniword/validation/rules/rsid_rule.rb', line 15 def code = "DOC-109" |
#description ⇒ Object
17 |
# File 'lib/uniword/validation/rules/rsid_rule.rb', line 17 def description = "Paragraphs should have rsidR and rsidRDefault attributes" |
#severity ⇒ Object
19 |
# File 'lib/uniword/validation/rules/rsid_rule.rb', line 19 def severity = "warning" |
#validity_rule ⇒ Object
16 |
# File 'lib/uniword/validation/rules/rsid_rule.rb', line 16 def validity_rule = "R12" |