Class: Uniword::Validation::Rules::FontTableSignatureRule

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

Overview

Validates font table signature completeness.

DOC-107: Font sig elements should have valid attributes Validity rule: R13

Constant Summary collapse

W_NS =
"http://schemas.openxmlformats.org/wordprocessingml/2006/main"
SIG_ATTRS =
%w[usb0 usb1 usb2 usb3 csb0 csb1].freeze

Instance Method Summary collapse

Instance Method Details

#applicable?(context) ⇒ Boolean

Returns:

  • (Boolean)


23
24
25
# File 'lib/uniword/validation/rules/font_table_signature_rule.rb', line 23

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

#categoryObject



20
# File 'lib/uniword/validation/rules/font_table_signature_rule.rb', line 20

def category = :fonts

#check(context) ⇒ Object



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
# File 'lib/uniword/validation/rules/font_table_signature_rule.rb', line 27

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

  doc.root.xpath(".//w:font", "w" => W_NS).each do |font|
    name = font["w:name"]
    sig = font.at_xpath("w:sig", "w" => W_NS)

    next unless sig

    missing = SIG_ATTRS.reject { |attr| sig["w:#{attr}"] }

    next if missing.empty?

    issues << issue(
      "Font '#{name}' sig element missing attributes: #{missing.join(', ')}",
      part: "word/fontTable.xml",
      severity: "warning",
      suggestion: "Add complete sig data for font '#{name}'.",
    )
  end

  issues
end

#codeObject



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

def code = "DOC-107"

#descriptionObject



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

def description = "Font table sig elements should have valid attributes"

#severityObject



21
# File 'lib/uniword/validation/rules/font_table_signature_rule.rb', line 21

def severity = "warning"

#validity_ruleObject



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

def validity_rule = "R13"