Sha256: 9a3a90d9cd601488371f6f94c686dffa891f1d820318655e388626fd95fe9278

Contents?: true

Size: 1.31 KB

Versions: 29

Compression:

Stored size: 1.31 KB

Contents

# encoding: UTF-8

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

# http://unicode.org/reports/tr35/tr35-general.html#Transforms
# http://unicode.org/cldr/utility/transform.jsp

module TwitterCldr
  module Transforms

    class FilteredRuleSet
      attr_reader :filter_rule, :transform_id

      def initialize(filter_rule, transform_id)
        @filter_rule = filter_rule
        @transform_id = transform_id
      end

      def foward?
        true
      end

      def backward?
        false
      end

      def is_filter_rule?
        false
      end

      def is_transform_rule?
        false
      end

      def is_conversion_rule?
        false
      end

      def invert
        raise NotInvertibleError,
          "cannot invert this #{self.class.name}"
      end

      def transform(text)
        rule_set.transform(text)
      end

      def rule_set
        @rule_set ||= begin
          rs = Transformer.get(transform_id)

          # replace any existing filters in all conversion rules and build
          # a new rule set
          new_rules = rs.rules.map do |rule|
            next rule unless rule.is_conversion_rule_set?
            ConversionRuleSet.new(filter_rule, nil, rule.rules)
          end

          RuleSet.new(new_rules, transform_id)
        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/filtered_rule_set.rb
twitter_cldr-6.12.1 lib/twitter_cldr/transforms/filtered_rule_set.rb
twitter_cldr-6.12.0 lib/twitter_cldr/transforms/filtered_rule_set.rb
twitter_cldr-6.11.5 lib/twitter_cldr/transforms/filtered_rule_set.rb
twitter_cldr-6.11.4 lib/twitter_cldr/transforms/filtered_rule_set.rb
twitter_cldr-6.11.3 lib/twitter_cldr/transforms/filtered_rule_set.rb
twitter_cldr-6.11.2 lib/twitter_cldr/transforms/filtered_rule_set.rb
twitter_cldr-6.11.1 lib/twitter_cldr/transforms/filtered_rule_set.rb
twitter_cldr-6.11.0 lib/twitter_cldr/transforms/filtered_rule_set.rb
twitter_cldr-6.10.0 lib/twitter_cldr/transforms/filtered_rule_set.rb
twitter_cldr-6.9.0 lib/twitter_cldr/transforms/filtered_rule_set.rb
twitter_cldr-6.8.0 lib/twitter_cldr/transforms/filtered_rule_set.rb
twitter_cldr-6.7.0 lib/twitter_cldr/transforms/filtered_rule_set.rb
twitter_cldr-6.6.2 lib/twitter_cldr/transforms/filtered_rule_set.rb
twitter_cldr-6.6.1 lib/twitter_cldr/transforms/filtered_rule_set.rb
twitter_cldr-6.6.0 lib/twitter_cldr/transforms/filtered_rule_set.rb
twitter_cldr-6.5.0 lib/twitter_cldr/transforms/filtered_rule_set.rb
twitter_cldr-6.4.0 lib/twitter_cldr/transforms/filtered_rule_set.rb
twitter_cldr-6.3.0 lib/twitter_cldr/transforms/filtered_rule_set.rb
twitter_cldr-6.2.0 lib/twitter_cldr/transforms/filtered_rule_set.rb