Class: Decode::Syntax::Match

Inherits:
Object
  • Object
show all
Defined in:
lib/decode/syntax/match.rb

Overview

Represents a match in the source text for syntax rewriting.

Direct Known Subclasses

Link

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#rangeObject (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

#offsetObject

Get the starting offset of this match.



31
32
33
# File 'lib/decode/syntax/match.rb', line 31

def offset
  @range.min
end

#sizeObject

Get the size of this match.



36
37
38
# File 'lib/decode/syntax/match.rb', line 36

def size
  @range.size
end