Class: Uniword::FindReplace::Matcher

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

Overview

Abstract matcher: decides whether a string matches and what to replace it with.

Subclasses implement matches? (returns MatchData or nil) and substitute (applies the replacement given MatchData). The engine drives both via apply, which performs one substitution pass over a single string and returns [new_string, count].

Direct Known Subclasses

RegexMatcher, StringMatcher

Instance Method Summary collapse

Instance Method Details

#apply(text) ⇒ Array(String, Integer)

Apply the matcher to one string, replacing every non-overlapping match. Returns the new string and the count of substitutions.

Parameters:

  • text (String)

    the text to scan

Returns:

  • (Array(String, Integer))

    new text and substitution count

Raises:

  • (NotImplementedError)


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

def apply(text)
  raise NotImplementedError
end