Class: TwitterCldr::Tokenizers::TokenRecognizer

Inherits:
Object
  • Object
show all
Defined in:
lib/twitter_cldr/tokenizers/tokenizer.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(token_type, regex, content = nil, &block) ⇒ TokenRecognizer

Returns a new instance of TokenRecognizer.



13
14
15
16
17
18
# File 'lib/twitter_cldr/tokenizers/tokenizer.rb', line 13

def initialize(token_type, regex, content = nil, &block)
  @token_type = token_type
  @regex = regex
  @content = content
  @cleaner = block
end

Instance Attribute Details

#cleanerObject (readonly)

Returns the value of attribute cleaner.



11
12
13
# File 'lib/twitter_cldr/tokenizers/tokenizer.rb', line 11

def cleaner
  @cleaner
end

#contentObject (readonly)

Returns the value of attribute content.



11
12
13
# File 'lib/twitter_cldr/tokenizers/tokenizer.rb', line 11

def content
  @content
end

#regexObject (readonly)

Returns the value of attribute regex.



11
12
13
# File 'lib/twitter_cldr/tokenizers/tokenizer.rb', line 11

def regex
  @regex
end

#token_typeObject (readonly)

Returns the value of attribute token_type.



11
12
13
# File 'lib/twitter_cldr/tokenizers/tokenizer.rb', line 11

def token_type
  @token_type
end

Instance Method Details

#clean(val) ⇒ Object



24
25
26
27
28
29
30
# File 'lib/twitter_cldr/tokenizers/tokenizer.rb', line 24

def clean(val)
  if cleaner
    cleaner.call(val)
  else
    val
  end
end

#recognizes?(text) ⇒ Boolean

Returns:

  • (Boolean)


20
21
22
# File 'lib/twitter_cldr/tokenizers/tokenizer.rb', line 20

def recognizes?(text)
  !!(text =~ regex)
end