Class: TwitterCldr::Segmentation::SegmentIterator
- Inherits:
-
Object
- Object
- TwitterCldr::Segmentation::SegmentIterator
- Defined in:
- lib/twitter_cldr/segmentation/segment_iterator.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#rule_set ⇒ Object
readonly
Returns the value of attribute rule_set.
Instance Method Summary collapse
- #each_boundary(str) {|0| ... } ⇒ Object
- #each_segment(str) ⇒ Object
-
#initialize(rule_set) ⇒ SegmentIterator
constructor
A new instance of SegmentIterator.
Constructor Details
#initialize(rule_set) ⇒ SegmentIterator
Returns a new instance of SegmentIterator.
11 12 13 |
# File 'lib/twitter_cldr/segmentation/segment_iterator.rb', line 11 def initialize(rule_set) @rule_set = rule_set end |
Instance Attribute Details
#rule_set ⇒ Object (readonly)
Returns the value of attribute rule_set.
9 10 11 |
# File 'lib/twitter_cldr/segmentation/segment_iterator.rb', line 9 def rule_set @rule_set end |
Instance Method Details
#each_boundary(str) {|0| ... } ⇒ Object
23 24 25 26 27 28 29 30 31 |
# File 'lib/twitter_cldr/segmentation/segment_iterator.rb', line 23 def each_boundary(str, &block) return to_enum(__method__, str) unless block_given? # implicit start of text boundary yield 0 cursor = create_cursor(str) rule_set.each_boundary(cursor, &block) end |
#each_segment(str) ⇒ Object
15 16 17 18 19 20 21 |
# File 'lib/twitter_cldr/segmentation/segment_iterator.rb', line 15 def each_segment(str) return to_enum(__method__, str) unless block_given? each_boundary(str).each_cons(2) do |start, stop| yield str[start...stop], start, stop end end |