class Match
Represents a match in the source text for syntax rewriting.
Definitions
def initialize(range)
Initialize a new match.
Signature
-
parameter
range
Range
The range of text this match covers.
Implementation
def initialize(range)
@range = range
end
def apply(source)
Apply the match to extract text from source.
Signature
-
parameter
source
String
The source text.
Implementation
def apply(source)
return source[range]
end
def apply(output, rewriter)
Apply the match to the output.
Signature
-
parameter
output
String
The output to append to.
-
parameter
rewriter
Rewriter
The rewriter instance.
Implementation
def apply(output, rewriter)
output << rewriter.text_for(@range)
return self.size
end
def <=>(other)
Compare matches by their starting position.
Signature
-
parameter
other
Match
The other match to compare.
Implementation
def <=> other
@range.min <=> other.range.min
end
def offset
Get the starting offset of this match.
Implementation
def offset
@range.min
end
def size
Get the size of this match.
Implementation
def size
@range.size
end