Class: TwitterCldr::Segmentation::SegmentIterator

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

Direct Known Subclasses

WordIterator

Instance Attribute Summary collapse

Instance Method Summary collapse

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_setObject (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

Yields:

  • (0)


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