Class: Uniword::FindReplace::Scope

Inherits:
Object
  • Object
show all
Defined in:
lib/uniword/find_replace/scope.rb

Overview

Abstract scope: knows how to enumerate text-bearing nodes in one part of the package and run a matcher over them.

Each subclass implements each_text_node, yielding [holder, accessor] pairs where holder is the object whose text we read/write and accessor is a TextAccessor value object with value and value= methods.

Open/closed: a new scope = a new subclass + registration in Engine::SCOPE_REGISTRY. Engine and other scopes are unchanged.

Defined Under Namespace

Classes: TextAccessor

Instance Method Summary collapse

Constructor Details

#initialize(document) ⇒ Scope

Returns a new instance of Scope.

Parameters:



18
19
20
# File 'lib/uniword/find_replace/scope.rb', line 18

def initialize(document)
  @document = document
end

Instance Method Details

#each_text_node {|holder, accessor| ... } ⇒ void

This method returns an undefined value.

Yield [holder, accessor] for every text node this scope covers. Engine applies the matcher to each accessor.

Yield Parameters:

Raises:

  • (NotImplementedError)


34
35
36
# File 'lib/uniword/find_replace/scope.rb', line 34

def each_text_node
  raise NotImplementedError
end

#nameSymbol

Returns scope name (e.g. :body, :headers).

Returns:

  • (Symbol)

    scope name (e.g. :body, :headers)

Raises:

  • (NotImplementedError)


23
24
25
# File 'lib/uniword/find_replace/scope.rb', line 23

def name
  raise NotImplementedError
end