Class: TwitterCldr::Transforms::VariableRule

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

Defined Under Namespace

Classes: Parser

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

#backward?, #forward?, #invert, #is_comment?, #is_conversion_rule?, #is_conversion_rule_set?, #is_filter_rule?, #is_transform_rule?, regexp_token_string, remove_comment, replace_symbols, #token_string, token_string, #token_value, token_value

Constructor Details

#initialize(name, value) ⇒ VariableRule

Returns a new instance of VariableRule.



66
67
68
69
# File 'lib/twitter_cldr/transforms/variable_rule.rb', line 66

def initialize(name, value)
  @name = name
  @value_tokens = value
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



64
65
66
# File 'lib/twitter_cldr/transforms/variable_rule.rb', line 64

def name
  @name
end

#value_tokensObject (readonly)

Returns the value of attribute value_tokens.



64
65
66
# File 'lib/twitter_cldr/transforms/variable_rule.rb', line 64

def value_tokens
  @value_tokens
end

Class Method Details

.accepts?(rule_text) ⇒ Boolean

Returns:

  • (Boolean)


49
50
51
# File 'lib/twitter_cldr/transforms/variable_rule.rb', line 49

def accepts?(rule_text)
  !!(rule_text =~ /\A[\s]*\$[\w]+[\s]*=/)
end

.parse(rule_text, symbol_table, index) ⇒ Object



37
38
39
40
41
42
43
44
45
46
47
# File 'lib/twitter_cldr/transforms/variable_rule.rb', line 37

def parse(rule_text, symbol_table, index)
  cleaned_rule_text = Rule.remove_comment(rule_text)
  tokens = tokenizer.tokenize(cleaned_rule_text)
  var_name, value_tokens = parser.parse(tokens)

  VariableRule.new(
    var_name, replace_symbols(
      value_tokens, symbol_table
    )
  )
end

Instance Method Details

#is_variable?Boolean

Returns:

  • (Boolean)


71
72
73
# File 'lib/twitter_cldr/transforms/variable_rule.rb', line 71

def is_variable?
  true
end