Sha256: ddc0efdeb4c16cbc0f2194ce2f219619a511824f01169a6eba8108090c25bf2d

Contents?: true

Size: 1.28 KB

Versions: 29

Compression:

Stored size: 1.28 KB

Contents

# encoding: UTF-8

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

module TwitterCldr
  module Transforms
    module Transforms

      class TransformPair
        attr_reader :filter, :transform

        def initialize(filter, transform)
          @filter = filter
          @transform = transform
        end

        def has_transform?
          transform && !transform.empty?
        end

        def has_filter?
          filter && !filter.empty?
        end

        def apply_to(cursor)
          cursor.set_text(rule_set.transform(cursor.text))
          cursor.reset_position
        end

        def null?
          false
        end

        def blank?
          false
        end

        private

        def rule_set
          @rule_set ||= if has_filter? && has_transform?
            FilteredRuleSet.new(filter_rule, transform)
          elsif has_transform?
            Transformer.get(transform)
          else
            raise NotImplementedError,
              'attempted to create a rule set with only a filter, which '\
              'has undefined behavior'
          end
        end

        def filter_rule
          @filter_rule ||= if has_filter?
            Filters::FilterRule.parse(filter, nil, nil)
          end
        end
      end

    end
  end
end

Version data entries

29 entries across 29 versions & 1 rubygems

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