Class: TwitterCldr::Transforms::RuleSet

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(rules, transform_id) ⇒ RuleSet

Returns a new instance of RuleSet.



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

def initialize(rules, transform_id)
  @rules = partition(rules)
  @transform_id = transform_id
end

Instance Attribute Details

#rulesObject (readonly)

Returns the value of attribute rules.



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

def rules
  @rules
end

#transform_idObject (readonly)

Returns the value of attribute transform_id.



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

def transform_id
  @transform_id
end

Instance Method Details

#invertObject



26
27
28
29
30
# File 'lib/twitter_cldr/transforms/rule_set.rb', line 26

def invert
  self.class.new(
    rules.reverse.map(&:invert), transform_id
  )
end

#transform(text) ⇒ Object



20
21
22
23
24
# File 'lib/twitter_cldr/transforms/rule_set.rb', line 20

def transform(text)
  cursor = Cursor.new(text.dup)
  rules.each { |rule| rule.apply_to(cursor) }
  cursor.text
end