Class: Uniword::Validation::Checkers::FootnoteReferenceChecker

Inherits:
LinkChecker
  • Object
show all
Defined in:
lib/uniword/validation/checkers/footnote_reference_checker.rb

Overview

Validates footnote and endnote references.

Responsibility: Validate footnote references point to existing notes. Single Responsibility: Footnote reference validation only.

Verifies:

  • Footnote/endnote targets exist in document

  • Reference IDs are valid

Configuration options:

  • check_targets_exist: Whether to verify footnote targets exist

Examples:

Create and use checker

checker = FootnoteReferenceChecker.new(config: {
  check_targets_exist: true
})
result = checker.check(footnote_ref, document)

Constant Summary collapse

DEFAULTS =

Default configuration values

{
  check_targets_exist: true,
}.freeze

Instance Attribute Summary

Attributes inherited from LinkChecker

#config

Instance Method Summary collapse

Methods inherited from LinkChecker

#initialize

Constructor Details

This class inherits a constructor from Uniword::Validation::LinkChecker

Instance Method Details

#can_check?(link) ⇒ Boolean

Check if this checker can validate the given link.

Examples:

checker.can_check?(footnote_ref) # => true

Parameters:

  • link (Object)

    The link to check

Returns:

  • (Boolean)

    true if link is a footnote reference



38
39
40
41
42
43
44
45
46
# File 'lib/uniword/validation/checkers/footnote_reference_checker.rb', line 38

def can_check?(link)
  return false unless enabled?

  # Check if link is a footnote reference
  link.respond_to?(:footnote_id) ||
    link.respond_to?(:endnote_id) ||
    (link.respond_to?(:type) && %i[footnote
                                   endnote].include?(link.type))
end

#check(link, document = nil) ⇒ ValidationResult

Validate the footnote reference.

Examples:

result = checker.check(footnote_ref, document)

Parameters:

  • link (Object)

    The link to validate

  • document (Object) (defaults to: nil)

    The document containing footnotes

Returns:



56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
# File 'lib/uniword/validation/checkers/footnote_reference_checker.rb', line 56

def check(link, document = nil)
  unless enabled?
    return ValidationResult.unknown(link,
                                    "Checker disabled")
  end

  unless config_value(:check_targets_exist,
                      DEFAULTS[:check_targets_exist])
    return ValidationResult.warning(
      link,
      "Footnote target checking disabled",
    )
  end

  unless document
    return ValidationResult.warning(
      link,
      "Cannot validate without document context",
    )
  end

  # Extract footnote/endnote ID
  note_id = extract_note_id(link)
  unless note_id
    return ValidationResult.failure(link,
                                    "No footnote ID specified")
  end

  # Determine note type
  note_type = determine_note_type(link)

  # Get footnotes/endnotes from document
  notes = extract_notes(document, note_type)

  # Check if note exists
  if note_exists?(note_id, notes)
    ValidationResult.success(
      link,
      metadata: {
        note_id: note_id,
        note_type: note_type,
        note_count: notes.size,
      },
    )
  else
    ValidationResult.failure(
      link,
      "#{note_type.to_s.capitalize} not found: #{note_id}",
      metadata: {
        note_id: note_id,
        note_type: note_type,
        available_notes: notes.keys,
      },
    )
  end
end