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)


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

def applicable?(_context)
  true
end

#categorySymbol

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

Returns:

  • (Symbol)


56
57
58
# File 'lib/uniword/validation/rules/base.rb', line 56

def category
  :general
end

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

Run the validation check.

Parameters:

Returns:



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

def check(_context)
  []
end

#codeString

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

Returns:

  • (String)


35
36
37
# File 'lib/uniword/validation/rules/base.rb', line 35

def code
  nil
end

#descriptionString?

Human-readable description of what this rule checks.

Returns:

  • (String, nil)


49
50
51
# File 'lib/uniword/validation/rules/base.rb', line 49

def description
  nil
end

#severityString

Default severity for issues from this rule.

Returns:

  • (String)

    “error”, “warning”, “info”, or “notice”



63
64
65
# File 'lib/uniword/validation/rules/base.rb', line 63

def severity
  "error"
end

#validity_ruleString?

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

Returns:

  • (String, nil)

    e.g. “R1”



42
43
44
# File 'lib/uniword/validation/rules/base.rb', line 42

def validity_rule
  nil
end