Sha256: a7e2948012d3acc6ce0811e1921f6d0c1014a374874cea9ef8726944d8a350e8

Contents?: true

Size: 779 Bytes

Versions: 1

Compression:

Stored size: 779 Bytes

Contents

# encoding: utf-8
#
module Picky

  module CharacterSubstituters # :nodoc:all

    # Substitutes Umlauts like
    # ä, ö, ü => ae, oe, ue.
    # (and more, see specs)
    #
    class WestEuropean

      def initialize
        @chars = ActiveSupport::Multibyte.proxy_class
      end

      def to_s
        self.class.name
      end

      def substitute text
        trans = @chars.new(text).normalize(:kd)

        # substitute special cases
        #
        trans.gsub!('ß', 'ss')

        # substitute umlauts (of A,O,U,a,o,u)
        #
        trans.gsub!(/([AOUaou])\314\210/u, '\1e')

        # get rid of ecutes, graves and …
        #
        trans.unpack('U*').select { |cp|
          cp < 0x0300 || cp > 0x035F
        }.pack('U*')
      end

    end

  end

end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
picky-3.0.0.pre1 lib/picky/character_substituters/west_european.rb