Class: TwitterCldr::Transforms::Transforms::TransformRule

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

Overview

Base class for transforms

Constant Summary

Constants inherited from Rule

Rule::STRING_TYPES

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Rule

#is_comment?, #is_conversion_rule?, #is_conversion_rule_set?, #is_filter_rule?, #is_variable?, regexp_token_string, remove_comment, replace_symbols, #token_string, token_string, #token_value, token_value

Constructor Details

#initialize(forward_form, backward_form) ⇒ TransformRule

Returns a new instance of TransformRule.



75
76
77
78
79
# File 'lib/twitter_cldr/transforms/transforms/transform_rule.rb', line 75

def initialize(forward_form, backward_form)
  @forward_form = forward_form
  @backward_form = backward_form
  after_initialize
end

Instance Attribute Details

#backward_formObject (readonly)

Returns the value of attribute backward_form.



73
74
75
# File 'lib/twitter_cldr/transforms/transforms/transform_rule.rb', line 73

def backward_form
  @backward_form
end

#forward_formObject (readonly)

Returns the value of attribute forward_form.



73
74
75
# File 'lib/twitter_cldr/transforms/transforms/transform_rule.rb', line 73

def forward_form
  @forward_form
end

Class Method Details

.accepts?(rule_text) ⇒ Boolean

Returns:

  • (Boolean)


26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/twitter_cldr/transforms/transforms/transform_rule.rb', line 26

def accepts?(rule_text)
  rule_text = Rule.remove_comment(rule_text)
  rule_text = rule_text[2..-2].strip
  tokens = tokenizer.tokenize(rule_text)
  forward_form, backward_form = parser.parse(tokens)

  transforms.any? do |transform|
    transform.accepts?(forward_form, backward_form)
  end
rescue Exception => e
  if $debug
    puts e.message
    puts e.backtrace.join("\n")
  end

  false
end

.blank?Boolean

Returns:

  • (Boolean)


48
49
50
# File 'lib/twitter_cldr/transforms/transforms/transform_rule.rb', line 48

def blank?
  false
end

.null?Boolean

Returns:

  • (Boolean)


44
45
46
# File 'lib/twitter_cldr/transforms/transforms/transform_rule.rb', line 44

def null?
  false
end

.parse(rule_text, symbol_table, index) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/twitter_cldr/transforms/transforms/transform_rule.rb', line 13

def parse(rule_text, symbol_table, index)
  rule_text = Rule.remove_comment(rule_text).strip
  rule_text = rule_text[2..-2].strip if rule_text.start_with?('::')
  tokens = tokenizer.tokenize(rule_text)
  forward_form, backward_form = parser.parse(tokens)

  transform_class = transforms.find do |transform|
    transform.accepts?(forward_form, backward_form)
  end

  transform_class.new(forward_form, backward_form)
end

Instance Method Details

#backward?Boolean

Returns:

  • (Boolean)


89
90
91
# File 'lib/twitter_cldr/transforms/transforms/transform_rule.rb', line 89

def backward?
  false
end

#forward?Boolean

Returns:

  • (Boolean)


85
86
87
# File 'lib/twitter_cldr/transforms/transforms/transform_rule.rb', line 85

def forward?
  !forward_form.null?
end

#invertObject



93
94
95
# File 'lib/twitter_cldr/transforms/transforms/transform_rule.rb', line 93

def invert
  self.class.new(backward_form, forward_form)
end

#is_transform_rule?Boolean

Returns:

  • (Boolean)


81
82
83
# File 'lib/twitter_cldr/transforms/transforms/transform_rule.rb', line 81

def is_transform_rule?
  true
end