Class: TwitterCldr::Transforms::Filters::UnicodeFilter

Inherits:
FilterRule
  • Object
show all
Defined in:
lib/twitter_cldr/transforms/filters/unicode_filter.rb

Constant Summary

Constants inherited from Rule

Rule::STRING_TYPES

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from FilterRule

#is_filter_rule?

Methods inherited from Rule

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

Constructor Details

#initialize(charset, direction) ⇒ UnicodeFilter

Returns a new instance of UnicodeFilter.



50
51
52
53
# File 'lib/twitter_cldr/transforms/filters/unicode_filter.rb', line 50

def initialize(charset, direction)
  @charset = charset
  @direction = direction
end

Instance Attribute Details

#charsetObject (readonly)

Returns the value of attribute charset.



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

def charset
  @charset
end

#directionObject (readonly)

Returns the value of attribute direction.



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

def direction
  @direction
end

Class Method Details

.accepts?(rule_text) ⇒ Boolean

Returns:

  • (Boolean)


25
26
27
# File 'lib/twitter_cldr/transforms/filters/unicode_filter.rb', line 25

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

.parse(rule_text, symbol_table) ⇒ Object



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

def parse(rule_text, symbol_table)
  rule_text = Rule.remove_comment(rule_text).strip
  rule_text = rule_text[2..-2].strip if rule_text.start_with?('::')
  direction = direction_for(rule_text)

  re = TwitterCldr::Shared::UnicodeRegex.compile(
    clean_rule(rule_text, direction)
  )

  # filters are always just a unicode set
  new(re.elements.first.to_set.to_set, direction)
end

Instance Method Details

#backward?Boolean

Returns:

  • (Boolean)


67
68
69
# File 'lib/twitter_cldr/transforms/filters/unicode_filter.rb', line 67

def backward?
  direction == :backward
end

#forward?Boolean

Returns:

  • (Boolean)


63
64
65
# File 'lib/twitter_cldr/transforms/filters/unicode_filter.rb', line 63

def forward?
  direction == :forward
end

#matches?(cursor) ⇒ Boolean

Returns:

  • (Boolean)


59
60
61
# File 'lib/twitter_cldr/transforms/filters/unicode_filter.rb', line 59

def matches?(cursor)
  charset.include?(cursor.text[cursor.position].ord)
end

#resolve(symbol_table) ⇒ Object



55
56
57
# File 'lib/twitter_cldr/transforms/filters/unicode_filter.rb', line 55

def resolve(symbol_table)
  self
end