Class: TwitterCldr::Transforms::Filters::RegexFilter

Inherits:
FilterRule
  • Object
show all
Defined in:
lib/twitter_cldr/transforms/filters/regex_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_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(regexp, direction) ⇒ RegexFilter

Returns a new instance of RegexFilter.



49
50
51
52
# File 'lib/twitter_cldr/transforms/filters/regex_filter.rb', line 49

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

Instance Attribute Details

#directionObject (readonly)

Returns the value of attribute direction.



47
48
49
# File 'lib/twitter_cldr/transforms/filters/regex_filter.rb', line 47

def direction
  @direction
end

#regexpObject (readonly)

Returns the value of attribute regexp.



47
48
49
# File 'lib/twitter_cldr/transforms/filters/regex_filter.rb', line 47

def regexp
  @regexp
end

Class Method Details

.accepts?(rule_text) ⇒ Boolean

Returns:

  • (Boolean)


24
25
26
# File 'lib/twitter_cldr/transforms/filters/regex_filter.rb', line 24

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
# File 'lib/twitter_cldr/transforms/filters/regex_filter.rb', line 12

def parse(rule_text, symbol_table)
  rule_text = Rule.remove_comment(rule_text)
  rule_text = rule_text[2..-2].strip
  direction = direction_for(rule_text)

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

  new(/#{str}/, direction)
end

Instance Method Details

#backward?Boolean

Returns:

  • (Boolean)


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

def backward?
  direction == :backward
end

#forward?Boolean

Returns:

  • (Boolean)


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

def forward?
  direction == :forward
end

#matches?(cursor) ⇒ Boolean

Returns:

  • (Boolean)


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

def matches?(cursor)
  idx = cursor.text.index(regexp, cursor.position)
  idx == cursor.position
end

#resolve(symbol_table) ⇒ Object



54
55
56
# File 'lib/twitter_cldr/transforms/filters/regex_filter.rb', line 54

def resolve(symbol_table)
  self
end