Sha256: c3dbee0e86d7ced40dc9d8a139c8082970245ca0c1edcc68da4265519843ce40

Contents?: true

Size: 1.16 KB

Versions: 1

Compression:

Stored size: 1.16 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 :QuickCheck, 'twitter_cldr/normalization/quick_check'
    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

1 entries across 1 versions & 1 rubygems

Version Path
twitter_cldr-3.0.0.beta1 lib/twitter_cldr/normalization.rb