Class: Uniword::Validation::Rules::SectionPropertiesRule
- Defined in:
- lib/uniword/validation/rules/section_properties_rule.rb
Overview
Validates that section properties exist with required children.
DOC-104: sectPr exists with pgSz and pgMar Validity rule: R11
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/section_properties_rule.rb', line 21 def applicable?(context) context.part_exists?("word/document.xml") end |
#category ⇒ Object
18 |
# File 'lib/uniword/validation/rules/section_properties_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 62 63 64 65 66 67 68 |
# File 'lib/uniword/validation/rules/section_properties_rule.rb', line 25 def check(context) issues = [] doc = context.document_xml return issues unless doc body = doc.root.at_xpath("//w:body", "w" => W_NS) unless body issues << issue("Document missing w:body element", part: "word/document.xml") return issues end sect_pr = body.at_xpath("w:sectPr", "w" => W_NS) unless sect_pr issues << issue( "Document body missing w:sectPr element", part: "word/document.xml", suggestion: "Add a w:sectPr with w:pgSz and w:pgMar " \ "to the end of w:body.", ) return issues end pg_sz = sect_pr.at_xpath("w:pgSz", "w" => W_NS) unless pg_sz issues << issue( "Section properties missing w:pgSz", part: "word/document.xml", suggestion: "Add <w:pgSz w:w=\"12240\" w:h=\"15840\"/>.", ) end pg_mar = sect_pr.at_xpath("w:pgMar", "w" => W_NS) unless pg_mar issues << issue( "Section properties missing w:pgMar", part: "word/document.xml", suggestion: "Add <w:pgMar w:top=\"1440\" w:right=\"1440\" " \ "w:bottom=\"1440\" w:left=\"1440\"/>.", ) end issues end |
#code ⇒ Object
15 |
# File 'lib/uniword/validation/rules/section_properties_rule.rb', line 15 def code = "DOC-104" |
#description ⇒ Object
17 |
# File 'lib/uniword/validation/rules/section_properties_rule.rb', line 17 def description = "Document body must have sectPr with pgSz and pgMar" |
#severity ⇒ Object
19 |
# File 'lib/uniword/validation/rules/section_properties_rule.rb', line 19 def severity = "error" |
#validity_rule ⇒ Object
16 |
# File 'lib/uniword/validation/rules/section_properties_rule.rb', line 16 def validity_rule = "R11" |