Class: TwitterCldr::Segmentation::Cursor

Inherits:
Object
  • Object
show all
Defined in:
lib/twitter_cldr/segmentation/cursor.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(text) ⇒ Cursor

Returns a new instance of Cursor.



12
13
14
15
16
# File 'lib/twitter_cldr/segmentation/cursor.rb', line 12

def initialize(text)
  @text = text
  @codepoints = text.codepoints
  reset
end

Instance Attribute Details

#codepointsObject (readonly)

Returns the value of attribute codepoints.



9
10
11
# File 'lib/twitter_cldr/segmentation/cursor.rb', line 9

def codepoints
  @codepoints
end

#positionObject

Returns the value of attribute position.



10
11
12
# File 'lib/twitter_cldr/segmentation/cursor.rb', line 10

def position
  @position
end

#textObject (readonly)

Returns the value of attribute text.



9
10
11
# File 'lib/twitter_cldr/segmentation/cursor.rb', line 9

def text
  @text
end

Instance Method Details

#advance(amount = 1) ⇒ Object



18
19
20
# File 'lib/twitter_cldr/segmentation/cursor.rb', line 18

def advance(amount = 1)
  @position += amount
end

#codepoint(pos = @position) ⇒ Object



30
31
32
# File 'lib/twitter_cldr/segmentation/cursor.rb', line 30

def codepoint(pos = @position)
  codepoints[pos]
end

#eos?Boolean

Returns:

  • (Boolean)


26
27
28
# File 'lib/twitter_cldr/segmentation/cursor.rb', line 26

def eos?
  position >= text.size
end

#lengthObject



34
35
36
# File 'lib/twitter_cldr/segmentation/cursor.rb', line 34

def length
  text.length
end

#resetObject



22
23
24
# File 'lib/twitter_cldr/segmentation/cursor.rb', line 22

def reset
  @position = 0
end