Class: TwitterCldr::Transforms::ConversionRuleSet
- Inherits:
-
Object
- Object
- TwitterCldr::Transforms::ConversionRuleSet
- Defined in:
- lib/twitter_cldr/transforms/conversion_rule_set.rb
Instance Attribute Summary collapse
-
#filter_rule ⇒ Object
readonly
Returns the value of attribute filter_rule.
-
#inverse_filter_rule ⇒ Object
readonly
Returns the value of attribute inverse_filter_rule.
-
#rule_index ⇒ Object
readonly
Returns the value of attribute rule_index.
-
#rules ⇒ Object
readonly
Returns the value of attribute rules.
Instance Method Summary collapse
- #apply_to(cursor) ⇒ Object
- #backward? ⇒ Boolean
- #forward? ⇒ Boolean
-
#initialize(filter_rule, inverse_filter_rule, rules) ⇒ ConversionRuleSet
constructor
A new instance of ConversionRuleSet.
- #invert ⇒ Object
- #is_conversion_rule? ⇒ Boolean
- #is_conversion_rule_set? ⇒ Boolean
- #is_filter_rule? ⇒ Boolean
- #is_transform_rule? ⇒ Boolean
Constructor Details
#initialize(filter_rule, inverse_filter_rule, rules) ⇒ ConversionRuleSet
Returns a new instance of ConversionRuleSet.
16 17 18 19 20 21 |
# File 'lib/twitter_cldr/transforms/conversion_rule_set.rb', line 16 def initialize(filter_rule, inverse_filter_rule, rules) @rules = rules @filter_rule = filter_rule @inverse_filter_rule = inverse_filter_rule @rule_index = build_rule_index(rules) end |
Instance Attribute Details
#filter_rule ⇒ Object (readonly)
Returns the value of attribute filter_rule.
13 14 15 |
# File 'lib/twitter_cldr/transforms/conversion_rule_set.rb', line 13 def filter_rule @filter_rule end |
#inverse_filter_rule ⇒ Object (readonly)
Returns the value of attribute inverse_filter_rule.
13 14 15 |
# File 'lib/twitter_cldr/transforms/conversion_rule_set.rb', line 13 def inverse_filter_rule @inverse_filter_rule end |
#rule_index ⇒ Object (readonly)
Returns the value of attribute rule_index.
14 15 16 |
# File 'lib/twitter_cldr/transforms/conversion_rule_set.rb', line 14 def rule_index @rule_index end |
#rules ⇒ Object (readonly)
Returns the value of attribute rules.
14 15 16 |
# File 'lib/twitter_cldr/transforms/conversion_rule_set.rb', line 14 def rules @rules end |
Instance Method Details
#apply_to(cursor) ⇒ Object
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/twitter_cldr/transforms/conversion_rule_set.rb', line 53 def apply_to(cursor) until cursor.eos? if filter_rule.matches?(cursor) rule_match = find_matching_rule_at(cursor) if rule_match start = rule_match.start stop = rule_match.stop replacement = rule_match.replacement puts "#{cursor.text[start...stop]} -> #{replacement}" if $debug cursor.text[start...stop] = replacement cursor.advance( replacement.size + rule_match.cursor_offset ) else cursor.advance end else cursor.advance end end end |
#backward? ⇒ Boolean
27 28 29 |
# File 'lib/twitter_cldr/transforms/conversion_rule_set.rb', line 27 def backward? false end |
#forward? ⇒ Boolean
23 24 25 |
# File 'lib/twitter_cldr/transforms/conversion_rule_set.rb', line 23 def forward? true end |
#invert ⇒ Object
47 48 49 50 51 |
# File 'lib/twitter_cldr/transforms/conversion_rule_set.rb', line 47 def invert ConversionRuleSet.new( inverse_filter_rule, filter_rule, inverted_rules ) end |
#is_conversion_rule? ⇒ Boolean
39 40 41 |
# File 'lib/twitter_cldr/transforms/conversion_rule_set.rb', line 39 def is_conversion_rule? false end |
#is_conversion_rule_set? ⇒ Boolean
43 44 45 |
# File 'lib/twitter_cldr/transforms/conversion_rule_set.rb', line 43 def is_conversion_rule_set? true end |
#is_filter_rule? ⇒ Boolean
31 32 33 |
# File 'lib/twitter_cldr/transforms/conversion_rule_set.rb', line 31 def is_filter_rule? false end |
#is_transform_rule? ⇒ Boolean
35 36 37 |
# File 'lib/twitter_cldr/transforms/conversion_rule_set.rb', line 35 def is_transform_rule? false end |