Class: Uniword::Validation::LinkChecker Abstract

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

Overview

This class is abstract.

Subclass and override #can_check? and #check

Base class for link checkers.

Responsibility: Define interface for link validation checkers. Single Responsibility: Provide checker contract only.

All link checkers inherit from this class and implement:

  • can_check?(link): Can this checker validate this link?

  • check(link, document): Perform validation

This follows the Strategy pattern - different checkers for different link types, all with the same interface.

Examples:

Create a custom checker

class MyChecker < LinkChecker
  def can_check?(link)
    link.respond_to?(:custom_field)
  end

  def check(link, document)
    # Validation logic
    ValidationResult.success(link)
  end
end

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config: {}) ⇒ LinkChecker

Initialize a new LinkChecker.

Examples:

Create a checker

checker = LinkChecker.new(config: { timeout: 10 })

Parameters:

  • config (Hash) (defaults to: {})

    Configuration options



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

def initialize(config: {})
  @config = config || {}
end

Instance Attribute Details

#configHash (readonly)

Returns Configuration for this checker.

Returns:

  • (Hash)

    Configuration for this checker



34
35
36
# File 'lib/uniword/validation/link_checker.rb', line 34

def config
  @config
end

Instance Method Details

#can_check?(link) ⇒ Boolean

This method is abstract.

Subclasses must implement this method

Check if this checker can validate the given link.

Examples:

checker.can_check?(hyperlink) # => true

Parameters:

  • link (Object)

    The link to check

Returns:

  • (Boolean)

    true if this checker can validate the link

Raises:

  • (NotImplementedError)


55
56
57
58
# File 'lib/uniword/validation/link_checker.rb', line 55

def can_check?(link)
  raise NotImplementedError,
        "#{self.class}#can_check? must be implemented"
end

#check(link, document = nil) ⇒ ValidationResult

This method is abstract.

Subclasses must implement this method

Validate the given link.

Examples:

result = checker.check(hyperlink, document)

Parameters:

  • link (Object)

    The link to validate

  • document (Object) (defaults to: nil)

    The document containing the link (for context)

Returns:

Raises:

  • (NotImplementedError)


70
71
72
73
# File 'lib/uniword/validation/link_checker.rb', line 70

def check(link, document = nil)
  raise NotImplementedError,
        "#{self.class}#check must be implemented"
end