Class: TwitterCldr::Transforms::FilteredRuleSet

Inherits:
Object
  • Object
show all
Defined in:
lib/twitter_cldr/transforms/filtered_rule_set.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(filter_rule, transform_id) ⇒ FilteredRuleSet

Returns a new instance of FilteredRuleSet.



15
16
17
18
# File 'lib/twitter_cldr/transforms/filtered_rule_set.rb', line 15

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

Instance Attribute Details

#filter_ruleObject (readonly)

Returns the value of attribute filter_rule.



13
14
15
# File 'lib/twitter_cldr/transforms/filtered_rule_set.rb', line 13

def filter_rule
  @filter_rule
end

#transform_idObject (readonly)

Returns the value of attribute transform_id.



13
14
15
# File 'lib/twitter_cldr/transforms/filtered_rule_set.rb', line 13

def transform_id
  @transform_id
end

Instance Method Details

#backward?Boolean

Returns:

  • (Boolean)


24
25
26
# File 'lib/twitter_cldr/transforms/filtered_rule_set.rb', line 24

def backward?
  false
end

#foward?Boolean

Returns:

  • (Boolean)


20
21
22
# File 'lib/twitter_cldr/transforms/filtered_rule_set.rb', line 20

def foward?
  true
end

#invertObject

Raises:



40
41
42
43
# File 'lib/twitter_cldr/transforms/filtered_rule_set.rb', line 40

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

#is_conversion_rule?Boolean

Returns:

  • (Boolean)


36
37
38
# File 'lib/twitter_cldr/transforms/filtered_rule_set.rb', line 36

def is_conversion_rule?
  false
end

#is_filter_rule?Boolean

Returns:

  • (Boolean)


28
29
30
# File 'lib/twitter_cldr/transforms/filtered_rule_set.rb', line 28

def is_filter_rule?
  false
end

#is_transform_rule?Boolean

Returns:

  • (Boolean)


32
33
34
# File 'lib/twitter_cldr/transforms/filtered_rule_set.rb', line 32

def is_transform_rule?
  false
end

#rule_setObject



49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/twitter_cldr/transforms/filtered_rule_set.rb', line 49

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

#transform(text) ⇒ Object



45
46
47
# File 'lib/twitter_cldr/transforms/filtered_rule_set.rb', line 45

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