Sha256: 54d198d153ba71bdaf407208549f40ab7d23dedf21c3c6d2aaae27f7f300e950
Contents?: true
Size: 1.3 KB
Versions: 23
Compression:
Stored size: 1.3 KB
Contents
# encoding: UTF-8 # Copyright 2012 Twitter, Inc # http://www.apache.org/licenses/LICENSE-2.0 module TwitterCldr module Segmentation class BreakIterator attr_reader :locale, :options def initialize(locale = TwitterCldr.locale, options = {}) @locale = locale @options = options end def each_sentence(str, &block) iter = iterator_for('sentence') iter.each_segment(str, &block) end def each_word(str, &block) iter = iterator_for('word') iter.each_segment(str, &block) end def each_grapheme_cluster(str, &block) iter = iterator_for('grapheme') iter.each_segment(str, &block) end def each_line(str, &block) iter = iterator_for('line') iter.each_segment(str, &block) end private def iterator_for(boundary_type) iterator_cache[boundary_type] ||= begin rule_set = RuleSet.create(locale, boundary_type, options) case boundary_type when 'line' LineIterator.new(rule_set) when 'word' WordIterator.new(rule_set) else SegmentIterator.new(rule_set) end end end def iterator_cache @iterator_cache ||= {} end end end end
Version data entries
23 entries across 23 versions & 1 rubygems