Class: TwitterCldr::Segmentation::BreakIterator

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(locale = TwitterCldr.locale, options = {}) ⇒ BreakIterator

Returns a new instance of BreakIterator.



24
25
26
27
# File 'lib/twitter_cldr/segmentation/break_iterator.rb', line 24

def initialize(locale = TwitterCldr.locale, options = {})
  @locale = locale
  @options = options
end

Instance Attribute Details

#localeObject (readonly)

Returns the value of attribute locale.



22
23
24
# File 'lib/twitter_cldr/segmentation/break_iterator.rb', line 22

def locale
  @locale
end

#optionsObject (readonly)

Returns the value of attribute options.



22
23
24
# File 'lib/twitter_cldr/segmentation/break_iterator.rb', line 22

def options
  @options
end

Class Method Details

.iterator_for(boundary_type, locale = nil, options = {}) ⇒ Object



10
11
12
13
14
15
16
17
18
19
# File 'lib/twitter_cldr/segmentation/break_iterator.rb', line 10

def iterator_for(boundary_type, locale = nil, options = {})
  rule_set = RuleSet.create(locale, boundary_type, options)

  case boundary_type
    when 'word'
      WordIterator.new(rule_set)
    else
      SegmentIterator.new(rule_set)
  end
end

Instance Method Details

#each_grapheme_cluster(str, &block) ⇒ Object



39
40
41
42
# File 'lib/twitter_cldr/segmentation/break_iterator.rb', line 39

def each_grapheme_cluster(str, &block)
  iter = iterator_for('grapheme')
  iter.each_segment(str, &block)
end

#each_line(str, &block) ⇒ Object



44
45
46
47
# File 'lib/twitter_cldr/segmentation/break_iterator.rb', line 44

def each_line(str, &block)
  iter = iterator_for('line')
  iter.each_segment(str, &block)
end

#each_sentence(str, &block) ⇒ Object



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

def each_sentence(str, &block)
  iter = iterator_for('sentence')
  iter.each_segment(str, &block)
end

#each_word(str, &block) ⇒ Object



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

def each_word(str, &block)
  iter = iterator_for('word')
  iter.each_segment(str, &block)
end