Sha256: e6601477337d4497d71cb399eb2933439984579cfb9dc8f4607b99e24a9669ab

Contents?: true

Size: 961 Bytes

Versions: 26

Compression:

Stored size: 961 Bytes

Contents

# encoding: UTF-8

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

require 'eprun'

module TwitterCldr
  module Normalization

    VALID_NORMALIZERS  = [:nfd, :nfkd, :nfc, :nfkc]
    DEFAULT_NORMALIZER = :nfd

    class << self

      def normalize(string, options = {})
        validate_form(form = extract_form_from(options))
        Eprun.normalize(string, form)
      end

      def normalized?(string, options = {})
        validate_form(form = extract_form_from(options))
        Eprun.normalized?(string, form)
      end

      private

      def extract_form_from(options)
        options.fetch(:using, DEFAULT_NORMALIZER).to_s.downcase.to_sym
      end

      def validate_form(form)
        unless VALID_NORMALIZERS.include?(form)
          raise ArgumentError.new("#{form.inspect} is not a valid normalizer "\
            "(valid normalizers are #{VALID_NORMALIZERS.join(', ')})")
        end
      end

    end
  end
end

Version data entries

26 entries across 26 versions & 1 rubygems

Version Path
twitter_cldr-6.13.0 lib/twitter_cldr/normalization.rb
twitter_cldr-6.12.1 lib/twitter_cldr/normalization.rb
twitter_cldr-6.12.0 lib/twitter_cldr/normalization.rb
twitter_cldr-6.11.5 lib/twitter_cldr/normalization.rb
twitter_cldr-6.11.4 lib/twitter_cldr/normalization.rb
twitter_cldr-6.11.3 lib/twitter_cldr/normalization.rb
twitter_cldr-6.11.2 lib/twitter_cldr/normalization.rb
twitter_cldr-6.11.1 lib/twitter_cldr/normalization.rb
twitter_cldr-6.11.0 lib/twitter_cldr/normalization.rb
twitter_cldr-6.10.0 lib/twitter_cldr/normalization.rb
twitter_cldr-6.9.0 lib/twitter_cldr/normalization.rb
twitter_cldr-6.8.0 lib/twitter_cldr/normalization.rb
twitter_cldr-6.7.0 lib/twitter_cldr/normalization.rb
twitter_cldr-6.6.2 lib/twitter_cldr/normalization.rb
twitter_cldr-6.6.1 lib/twitter_cldr/normalization.rb
twitter_cldr-6.6.0 lib/twitter_cldr/normalization.rb
twitter_cldr-6.5.0 lib/twitter_cldr/normalization.rb
twitter_cldr-6.4.0 lib/twitter_cldr/normalization.rb
twitter_cldr-6.3.0 lib/twitter_cldr/normalization.rb
twitter_cldr-6.2.0 lib/twitter_cldr/normalization.rb