Class: Decode::Syntax::Match
- Inherits:
-
Object
- Object
- Decode::Syntax::Match
- Defined in:
- lib/decode/syntax/match.rb
Overview
Represents a match in the source text for syntax rewriting.
Direct Known Subclasses
Instance Attribute Summary collapse
-
#range ⇒ Object
readonly
Returns the value of attribute range.
Instance Method Summary collapse
-
#<=>(other) ⇒ Object
Compare matches by their starting position.
-
#apply(output, rewriter) ⇒ Object
Apply the match to the output.
-
#initialize(range) ⇒ Match
constructor
Initialize a new match.
-
#offset ⇒ Object
Get the starting offset of this match.
-
#size ⇒ Object
Get the size of this match.
Constructor Details
#initialize(range) ⇒ Match
Initialize a new match.
12 13 14 |
# File 'lib/decode/syntax/match.rb', line 12 def initialize(range) @range = range end |
Instance Attribute Details
#range ⇒ Object (readonly)
Returns the value of attribute range.
16 17 18 |
# File 'lib/decode/syntax/match.rb', line 16 def range @range end |
Instance Method Details
#<=>(other) ⇒ Object
Compare matches by their starting position.
26 27 28 |
# File 'lib/decode/syntax/match.rb', line 26 def <=> other @range.min <=> other.range.min end |
#apply(output, rewriter) ⇒ Object
Apply the match to the output.
20 21 22 |
# File 'lib/decode/syntax/match.rb', line 20 def apply(source) return source[range] end |
#offset ⇒ Object
Get the starting offset of this match.
31 32 33 |
# File 'lib/decode/syntax/match.rb', line 31 def offset @range.min end |
#size ⇒ Object
Get the size of this match.
36 37 38 |
# File 'lib/decode/syntax/match.rb', line 36 def size @range.size end |