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
21
22
23
24
# File 'lib/twitter_cldr/segmentation/cursor.rb', line 18

def advance(amount = 1)
  if @position + amount > text.size
    @position = text.size
  else
    @position += amount
  end
end

#codepoint(pos = @position) ⇒ Object



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

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

#eos?Boolean

Returns:

  • (Boolean)


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

def eos?
  position >= text.size
end

#lengthObject



38
39
40
# File 'lib/twitter_cldr/segmentation/cursor.rb', line 38

def length
  text.length
end

#resetObject



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

def reset
  @position = 0
end