Class: Uniword::Validation::Rules::McIgnorableNamespaceRule

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

Overview

Validates that mc:Ignorable namespace prefixes have xmlns declarations.

DOC-100: mc:Ignorable lists prefixes that must have xmlns in scope Validity rule: R1

Constant Summary collapse

MC_NS =
"http://schemas.openxmlformats.org/markup-compatibility/2006"
PARTS =
[
  "word/document.xml",
  "word/styles.xml",
  "word/settings.xml",
  "word/numbering.xml",
  "word/fontTable.xml",
  "word/webSettings.xml",
].freeze

Instance Method Summary collapse

Instance Method Details

#applicable?(context) ⇒ Boolean

Returns:

  • (Boolean)


30
31
32
# File 'lib/uniword/validation/rules/mc_ignorable_namespace_rule.rb', line 30

def applicable?(context)
  PARTS.any? { |p| context.part_exists?(p) }
end

#categoryObject



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

def category = :namespaces

#check(context) ⇒ Object



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/uniword/validation/rules/mc_ignorable_namespace_rule.rb', line 34

def check(context)
  issues = []

  PARTS.each do |part_name|
    next unless context.part_exists?(part_name)

    doc = context.part(part_name)
    next unless doc

    root = doc.root
    next unless root

    ignorable_attr = root.attribute("Ignorable") ||
      root.attributes.find { |a| a.name == "Ignorable" }
    next unless ignorable_attr && !ignorable_attr.value.strip.empty?

    prefixes = ignorable_attr.value.strip.split(/\s+/)
    check_prefixes(root, prefixes, part_name, issues)
  end

  issues
end

#codeObject



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

def code = "DOC-100"

#descriptionObject



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

def description = "mc:Ignorable prefixes must have xmlns declarations in scope"

#severityObject



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

def severity = "error"

#validity_ruleObject



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

def validity_rule = "R1"