Sha256: 435db4cee5de4ba12cabe9acfb102941b1fc47b62f88132b4802e09ab0180b1b

Contents?: true

Size: 1.31 KB

Versions: 13

Compression:

Stored size: 1.31 KB

Contents

# encoding: UTF-8

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

module TwitterCldr
  module Transforms
    module Transforms

      class NormalizationTransform < TransformRule
        class << self
          def accepts?(forward_form, backward_form)
            valid_form?(forward_form) && valid_form?(backward_form)
          end

          private

          def valid_form?(form)
            !form || (
              form && TwitterCldr::Normalization::VALID_NORMALIZERS.include?(
                form.transform.downcase.to_sym
              )
            )
          end
        end

        attr_reader :forward_transform, :backward_transform

        def apply_to(cursor)
          if forward_transform
            cursor.set_text(
              TwitterCldr::Normalization.normalize(
                cursor.text, using: forward_transform
              )
            )

            cursor.reset_position
          end
        end

        private

        def after_initialize
          @forward_transform = symbolize_transform(forward_form)
          @backward_transform = symbolize_transform(backward_form)
        end

        def symbolize_transform(form)
          if form && form.has_transform?
            form.transform.downcase.to_sym
          end
        end
      end

    end
  end
end

Version data entries

13 entries across 13 versions & 2 rubygems

Version Path
metanorma-cli-1.3.4 gems/ruby/2.6.0/gems/twitter_cldr-4.4.5/lib/twitter_cldr/transforms/transforms/normalization_transform.rb
metanorma-cli-1.3.3.1 gems/ruby/2.6.0/gems/twitter_cldr-4.4.5/lib/twitter_cldr/transforms/transforms/normalization_transform.rb
twitter_cldr-4.4.5 lib/twitter_cldr/transforms/transforms/normalization_transform.rb
twitter_cldr-4.4.4 lib/twitter_cldr/transforms/transforms/normalization_transform.rb
twitter_cldr-4.4.3 lib/twitter_cldr/transforms/transforms/normalization_transform.rb
twitter_cldr-4.4.2 lib/twitter_cldr/transforms/transforms/normalization_transform.rb
twitter_cldr-4.4.1 lib/twitter_cldr/transforms/transforms/normalization_transform.rb
twitter_cldr-4.4.0 lib/twitter_cldr/transforms/transforms/normalization_transform.rb
twitter_cldr-4.3.1 lib/twitter_cldr/transforms/transforms/normalization_transform.rb
twitter_cldr-4.3.0 lib/twitter_cldr/transforms/transforms/normalization_transform.rb
twitter_cldr-4.2.0 lib/twitter_cldr/transforms/transforms/normalization_transform.rb
twitter_cldr-4.1.0 lib/twitter_cldr/transforms/transforms/normalization_transform.rb
twitter_cldr-4.0.0 lib/twitter_cldr/transforms/transforms/normalization_transform.rb