Class: Parslet::Position

Inherits:
Object
  • Object
show all
Includes:
Comparable
Defined in:
lib/parslet/position.rb

Overview

Encapsules the concept of a position inside a string.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(string, bytepos) ⇒ Position

Returns a new instance of Position.



9
10
11
12
# File 'lib/parslet/position.rb', line 9

def initialize string, bytepos
  @string = string
  @bytepos = bytepos
end

Instance Attribute Details

#byteposObject (readonly)

Returns the value of attribute bytepos.



5
6
7
# File 'lib/parslet/position.rb', line 5

def bytepos
  @bytepos
end

Instance Method Details

#<=>(b) ⇒ Object



18
19
20
# File 'lib/parslet/position.rb', line 18

def <=> b
  self.bytepos <=> b.bytepos
end

#charposObject



14
15
16
# File 'lib/parslet/position.rb', line 14

def charpos
  @string.byteslice(0, @bytepos).size
end