Class: TwitterCldr::Tokenizers::TokenRecognizer
- Inherits:
-
Object
- Object
- TwitterCldr::Tokenizers::TokenRecognizer
- Defined in:
- lib/twitter_cldr/tokenizers/tokenizer.rb
Instance Attribute Summary collapse
-
#cleaner ⇒ Object
readonly
Returns the value of attribute cleaner.
-
#content ⇒ Object
readonly
Returns the value of attribute content.
-
#regex ⇒ Object
readonly
Returns the value of attribute regex.
-
#token_type ⇒ Object
readonly
Returns the value of attribute token_type.
Instance Method Summary collapse
- #clean(val) ⇒ Object
-
#initialize(token_type, regex, content = nil, &block) ⇒ TokenRecognizer
constructor
A new instance of TokenRecognizer.
- #recognizes?(text) ⇒ Boolean
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
#cleaner ⇒ Object (readonly)
Returns the value of attribute cleaner.
11 12 13 |
# File 'lib/twitter_cldr/tokenizers/tokenizer.rb', line 11 def cleaner @cleaner end |
#content ⇒ Object (readonly)
Returns the value of attribute content.
11 12 13 |
# File 'lib/twitter_cldr/tokenizers/tokenizer.rb', line 11 def content @content end |
#regex ⇒ Object (readonly)
Returns the value of attribute regex.
11 12 13 |
# File 'lib/twitter_cldr/tokenizers/tokenizer.rb', line 11 def regex @regex end |
#token_type ⇒ Object (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
20 21 22 |
# File 'lib/twitter_cldr/tokenizers/tokenizer.rb', line 20 def recognizes?(text) !!(text =~ regex) end |