Sha256: 6264d8124f59e6867abbb96fd76130a843ca84b52d9fff2d15459ad819525089

Contents?: true

Size: 1 KB

Versions: 13

Compression:

Stored size: 1 KB

Contents

# encoding: UTF-8

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

module TwitterCldr
  module Transforms
    module Transforms

      class NamedTransform < TransformRule
        Transformer = TwitterCldr::Transforms::Transformer

        class << self
          def accepts?(forward_form, backward_form)
            exists?(forward_form) && exists?(backward_form)
          end

          private

          def exists?(form)
            !form || Transformer.exists?(form.transform)
          end
        end

        def apply_to(cursor)
          if forward_form
            rule_set = forward_form.to_rule_set
            cursor.set_text(rule_set.transform(cursor.text))
            cursor.reset_position
          end
        end

        private

        def after_initialize
          if forward_form
            @backward_form = TransformPair.new(
              nil, TransformId.parse(forward_form.transform).reverse.to_s
            )
          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/named_transform.rb
metanorma-cli-1.3.3.1 gems/ruby/2.6.0/gems/twitter_cldr-4.4.5/lib/twitter_cldr/transforms/transforms/named_transform.rb
twitter_cldr-4.4.5 lib/twitter_cldr/transforms/transforms/named_transform.rb
twitter_cldr-4.4.4 lib/twitter_cldr/transforms/transforms/named_transform.rb
twitter_cldr-4.4.3 lib/twitter_cldr/transforms/transforms/named_transform.rb
twitter_cldr-4.4.2 lib/twitter_cldr/transforms/transforms/named_transform.rb
twitter_cldr-4.4.1 lib/twitter_cldr/transforms/transforms/named_transform.rb
twitter_cldr-4.4.0 lib/twitter_cldr/transforms/transforms/named_transform.rb
twitter_cldr-4.3.1 lib/twitter_cldr/transforms/transforms/named_transform.rb
twitter_cldr-4.3.0 lib/twitter_cldr/transforms/transforms/named_transform.rb
twitter_cldr-4.2.0 lib/twitter_cldr/transforms/transforms/named_transform.rb
twitter_cldr-4.1.0 lib/twitter_cldr/transforms/transforms/named_transform.rb
twitter_cldr-4.0.0 lib/twitter_cldr/transforms/transforms/named_transform.rb