Sha256: 1a7bd322bd7818c8a1fb19d76554ab3e3480004534f663f4e98c2cbfb1644baa

Contents?: true

Size: 1.28 KB

Versions: 24

Compression:

Stored size: 1.28 KB

Contents

# encoding: UTF-8

# Copyright 2012 Twitter, Inc
# http://www.apache.org/licenses/LICENSE-2.0

module TwitterCldr
  module Segmentation
    class RuleSet

      class << self
        def create(locale, boundary_type, options = {})
          new(locale, StateMachine.instance(boundary_type, locale), options)
        end
      end

      attr_reader :locale, :state_machine
      attr_accessor :use_uli_exceptions

      alias_method :use_uli_exceptions?, :use_uli_exceptions

      def initialize(locale, state_machine, options)
        @locale = locale
        @state_machine = state_machine
        @use_uli_exceptions = options.fetch(
          :use_uli_exceptions, false
        )
      end

      def each_boundary(cursor, stop = cursor.length)
        return to_enum(__method__, cursor, stop) unless block_given?

        until cursor.position >= stop || cursor.eos?
          state_machine.handle_next(cursor)
          yield cursor.position if suppressions.should_break?(cursor)
        end
      end

      def boundary_type
        state_machine.boundary_type
      end

      private

      def suppressions
        @suppressions ||= if use_uli_exceptions?
          Suppressions.instance(boundary_type, locale)
        else
          NullSuppressions.instance
        end
      end
    end
  end
end

Version data entries

24 entries across 24 versions & 1 rubygems

Version Path
twitter_cldr-6.12.0 lib/twitter_cldr/segmentation/rule_set.rb
twitter_cldr-6.11.5 lib/twitter_cldr/segmentation/rule_set.rb
twitter_cldr-6.11.4 lib/twitter_cldr/segmentation/rule_set.rb
twitter_cldr-6.11.3 lib/twitter_cldr/segmentation/rule_set.rb
twitter_cldr-6.11.2 lib/twitter_cldr/segmentation/rule_set.rb
twitter_cldr-6.11.1 lib/twitter_cldr/segmentation/rule_set.rb
twitter_cldr-6.11.0 lib/twitter_cldr/segmentation/rule_set.rb
twitter_cldr-6.10.0 lib/twitter_cldr/segmentation/rule_set.rb
twitter_cldr-6.9.0 lib/twitter_cldr/segmentation/rule_set.rb
twitter_cldr-6.8.0 lib/twitter_cldr/segmentation/rule_set.rb
twitter_cldr-6.7.0 lib/twitter_cldr/segmentation/rule_set.rb
twitter_cldr-6.6.2 lib/twitter_cldr/segmentation/rule_set.rb
twitter_cldr-6.6.1 lib/twitter_cldr/segmentation/rule_set.rb
twitter_cldr-6.6.0 lib/twitter_cldr/segmentation/rule_set.rb
twitter_cldr-6.5.0 lib/twitter_cldr/segmentation/rule_set.rb
twitter_cldr-6.4.0 lib/twitter_cldr/segmentation/rule_set.rb
twitter_cldr-6.3.0 lib/twitter_cldr/segmentation/rule_set.rb
twitter_cldr-6.2.0 lib/twitter_cldr/segmentation/rule_set.rb
twitter_cldr-6.1.0 lib/twitter_cldr/segmentation/rule_set.rb
twitter_cldr-6.0.2 lib/twitter_cldr/segmentation/rule_set.rb