Class: TwitterCldr::Segmentation::Cursor
- Inherits:
-
Object
- Object
- TwitterCldr::Segmentation::Cursor
- Defined in:
- lib/twitter_cldr/segmentation/cursor.rb
Instance Attribute Summary collapse
-
#codepoints ⇒ Object
readonly
Returns the value of attribute codepoints.
-
#position ⇒ Object
Returns the value of attribute position.
-
#text ⇒ Object
readonly
Returns the value of attribute text.
Instance Method Summary collapse
- #advance(amount = 1) ⇒ Object
- #codepoint(pos = @position) ⇒ Object
- #eos? ⇒ Boolean
-
#initialize(text) ⇒ Cursor
constructor
A new instance of Cursor.
- #length ⇒ Object
- #reset ⇒ Object
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
#codepoints ⇒ Object (readonly)
Returns the value of attribute codepoints.
9 10 11 |
# File 'lib/twitter_cldr/segmentation/cursor.rb', line 9 def codepoints @codepoints end |
#position ⇒ Object
Returns the value of attribute position.
10 11 12 |
# File 'lib/twitter_cldr/segmentation/cursor.rb', line 10 def position @position end |
#text ⇒ Object (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
30 31 32 |
# File 'lib/twitter_cldr/segmentation/cursor.rb', line 30 def eos? position >= text.size end |
#length ⇒ Object
38 39 40 |
# File 'lib/twitter_cldr/segmentation/cursor.rb', line 38 def length text.length end |
#reset ⇒ Object
26 27 28 |
# File 'lib/twitter_cldr/segmentation/cursor.rb', line 26 def reset @position = 0 end |