Class: Uniword::Validation::Rules::Base

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

Overview

Base class for all document semantic validation rules.

Follows the Open/Closed Principle: new rules can be added by subclassing and registering, without modifying existing code.

Examples:

Implement a custom rule

class MyRule < Base
  def code = "CUSTOM-001"
  def category = :custom
  def severity = "warning"

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

  def check(context)
    issues = []
    # ... validation logic ...
    issues
  end
end

Uniword::Validation::Rules.register(MyRule)

Instance Method Summary collapse

Instance Method Details

#applicable?(_context) ⇒ Boolean

Check if this rule applies to the given document context.

Parameters:

Returns:

  • (Boolean)


79
80
81
# File 'lib/uniword/validation/rules/base.rb', line 79

def applicable?(_context)
  true
end

#categorySymbol

Category for grouping (e.g., :styles, :footnotes).

Returns:

  • (Symbol)


54
55
56
# File 'lib/uniword/validation/rules/base.rb', line 54

def category
  :general
end

#check(_context) ⇒ Array<Report::ValidationIssue>

Run the validation check.

Parameters:

Returns:



87
88
89
# File 'lib/uniword/validation/rules/base.rb', line 87

def check(_context)
  []
end

#codeString

Unique code for this rule (e.g., "DOC-020").

Returns:

  • (String)


33
34
35
# File 'lib/uniword/validation/rules/base.rb', line 33

def code
  nil
end

#context_typeSymbol

The context type this rule consumes. The Engine runs a rule only when the context's type matches: :package rules validate an on-disk DOCX via DocumentContext; :model rules validate an in-memory document model via ModelContext (see ModelRule).

Returns:

  • (Symbol)

    :package or :model



71
72
73
# File 'lib/uniword/validation/rules/base.rb', line 71

def context_type
  :package
end

#descriptionString?

Human-readable description of what this rule checks.

Returns:

  • (String, nil)


47
48
49
# File 'lib/uniword/validation/rules/base.rb', line 47

def description
  nil
end

#severityString

Default severity for issues from this rule.

Returns:

  • (String)

    "error", "warning", "info", or "notice"



61
62
63
# File 'lib/uniword/validation/rules/base.rb', line 61

def severity
  "error"
end

#validity_ruleString?

Reference to the validity rule in docs/docx-valid/rules/.

Returns:

  • (String, nil)

    e.g. "R1"



40
41
42
# File 'lib/uniword/validation/rules/base.rb', line 40

def validity_rule
  nil
end