Sha256: 1939d6a365fe9b24bed4bd505c0096f8c44a4203eb1f0f3833f24fcbc44d84f2

Contents?: true

Size: 1.07 KB

Versions: 14

Compression:

Stored size: 1.07 KB

Contents

# encoding: UTF-8

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

module TwitterCldr
  module Normalization
    autoload :Base,   'twitter_cldr/normalization/base'
    autoload :Hangul, 'twitter_cldr/normalization/hangul'
    autoload :NFC,    'twitter_cldr/normalization/nfc'
    autoload :NFD,    'twitter_cldr/normalization/nfd'
    autoload :NFKC,   'twitter_cldr/normalization/nfkc'
    autoload :NFKD,   'twitter_cldr/normalization/nfkd'

    VALID_NORMALIZERS  = [:NFD, :NFKD, :NFC, :NFKC]
    DEFAULT_NORMALIZER = :NFD

    class << self

      def normalize(string, options = {})
        normalizer(options[:using] || DEFAULT_NORMALIZER).normalize(string)
      end

      private

      def normalizer(normalizer_name)
        const_name = normalizer_name.to_s.upcase.to_sym

        if VALID_NORMALIZERS.include?(const_name)
          const_get(const_name)
        else
          raise ArgumentError.new("#{normalizer_name.inspect} is not a valid normalizer (valid normalizers are #{VALID_NORMALIZERS.join(', ')})")
        end
      end

    end
  end
end

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
twitter_cldr-2.4.3 lib/twitter_cldr/normalization.rb
twitter_cldr-2.4.2 lib/twitter_cldr/normalization.rb
twitter_cldr-2.4.1 lib/twitter_cldr/normalization.rb
twitter_cldr-2.4.0 lib/twitter_cldr/normalization.rb
twitter_cldr-2.2.0 lib/twitter_cldr/normalization.rb
twitter_cldr-2.1.1 lib/twitter_cldr/normalization.rb
twitter_cldr-2.1.0 lib/twitter_cldr/normalization.rb
twitter_cldr-2.0.2 lib/twitter_cldr/normalization.rb
twitter_cldr-2.0.1 lib/twitter_cldr/normalization.rb
twitter_cldr-2.0.0 lib/twitter_cldr/normalization.rb
twitter_cldr-1.9.1 lib/twitter_cldr/normalization.rb
twitter_cldr-1.9.0 lib/twitter_cldr/normalization.rb
twitter_cldr-1.8.1 lib/twitter_cldr/normalization.rb
twitter_cldr-1.8.0 lib/twitter_cldr/normalization.rb