Class: ICU::BreakIterator
- Inherits:
-
Object
- Object
- ICU::BreakIterator
- Includes:
- Enumerable
- Defined in:
- lib/ffi-icu/break_iterator.rb
Constant Summary collapse
- DONE =
-1
Instance Attribute Summary collapse
-
#text ⇒ Object
Returns the value of attribute text.
Class Method Summary collapse
Instance Method Summary collapse
- #boundary?(offset) ⇒ Boolean
- #current ⇒ Object
- #each ⇒ Object
- #each_substring ⇒ Object
- #first ⇒ Object
- #following(offset) ⇒ Object
-
#initialize(type, locale) ⇒ BreakIterator
constructor
A new instance of BreakIterator.
- #last ⇒ Object
- #next ⇒ Object
- #preceding(offset) ⇒ Object
- #previous ⇒ Object
- #substrings ⇒ Object
Constructor Details
#initialize(type, locale) ⇒ BreakIterator
Returns a new instance of BreakIterator.
17 18 19 20 |
# File 'lib/ffi-icu/break_iterator.rb', line 17 def initialize(type, locale) ptr = Lib.check_error { |err| Lib.ubrk_open(type, locale, nil, 0, err) } @iterator = FFI::AutoPointer.new(ptr, Lib.method(:ubrk_close)) end |
Instance Attribute Details
#text ⇒ Object
Returns the value of attribute text.
7 8 9 |
# File 'lib/ffi-icu/break_iterator.rb', line 7 def text @text end |
Class Method Details
Instance Method Details
#boundary?(offset) ⇒ Boolean
90 91 92 |
# File 'lib/ffi-icu/break_iterator.rb', line 90 def boundary?(offset) Lib.ubrk_isBoundary(@iterator, Integer(offset)) != 0 end |
#current ⇒ Object
86 87 88 |
# File 'lib/ffi-icu/break_iterator.rb', line 86 def current Lib.ubrk_current(@iterator) end |
#each ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/ffi-icu/break_iterator.rb', line 30 def each return to_enum(:each) unless block_given? int = first while int != DONE yield(int) int = self.next end self end |
#each_substring ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/ffi-icu/break_iterator.rb', line 43 def each_substring return to_enum(:each_substring) unless block_given? # each_char needed for 1.8, where String#[] works on bytes, not characters chars = text.each_char.to_a low = first while (high = self.next) != DONE yield(chars[low...high].join) low = high end self end |
#first ⇒ Object
70 71 72 |
# File 'lib/ffi-icu/break_iterator.rb', line 70 def first Lib.ubrk_first(@iterator) end |
#following(offset) ⇒ Object
82 83 84 |
# File 'lib/ffi-icu/break_iterator.rb', line 82 def following(offset) Lib.ubrk_following(@iterator, Integer(offset)) end |
#last ⇒ Object
74 75 76 |
# File 'lib/ffi-icu/break_iterator.rb', line 74 def last Lib.ubrk_last(@iterator) end |
#next ⇒ Object
62 63 64 |
# File 'lib/ffi-icu/break_iterator.rb', line 62 def next Lib.ubrk_next(@iterator) end |
#preceding(offset) ⇒ Object
78 79 80 |
# File 'lib/ffi-icu/break_iterator.rb', line 78 def preceding(offset) Lib.ubrk_preceding(@iterator, Integer(offset)) end |
#previous ⇒ Object
66 67 68 |
# File 'lib/ffi-icu/break_iterator.rb', line 66 def previous Lib.ubrk_next(@iterator) end |
#substrings ⇒ Object
58 59 60 |
# File 'lib/ffi-icu/break_iterator.rb', line 58 def substrings each_substring.to_a end |