Class: SocialTokenizer::TokenType
- Inherits:
-
Object
- Object
- SocialTokenizer::TokenType
- Includes:
- ActiveModel::Model, ActiveModel::Validations
- Defined in:
- lib/social_tokenizer/token_type.rb
Instance Attribute Summary collapse
-
#formatter ⇒ Object
Returns the value of attribute formatter.
-
#key ⇒ Object
Returns the value of attribute key.
-
#pattern ⇒ Object
Returns the value of attribute pattern.
-
#replacement ⇒ Object
Returns the value of attribute replacement.
-
#tokens ⇒ Object
Returns the value of attribute tokens.
Class Method Summary collapse
Instance Method Summary collapse
- #check_token(token_string) ⇒ Object
-
#initialize(attributes) ⇒ TokenType
constructor
A new instance of TokenType.
Constructor Details
#initialize(attributes) ⇒ TokenType
Returns a new instance of TokenType.
9 10 11 12 |
# File 'lib/social_tokenizer/token_type.rb', line 9 def initialize(attributes) super attributes self.tokens = [] end |
Instance Attribute Details
#formatter ⇒ Object
Returns the value of attribute formatter.
6 7 8 |
# File 'lib/social_tokenizer/token_type.rb', line 6 def formatter @formatter end |
#key ⇒ Object
Returns the value of attribute key.
6 7 8 |
# File 'lib/social_tokenizer/token_type.rb', line 6 def key @key end |
#pattern ⇒ Object
Returns the value of attribute pattern.
6 7 8 |
# File 'lib/social_tokenizer/token_type.rb', line 6 def pattern @pattern end |
#replacement ⇒ Object
Returns the value of attribute replacement.
6 7 8 |
# File 'lib/social_tokenizer/token_type.rb', line 6 def replacement @replacement end |
#tokens ⇒ Object
Returns the value of attribute tokens.
6 7 8 |
# File 'lib/social_tokenizer/token_type.rb', line 6 def tokens @tokens end |
Class Method Details
.all ⇒ Object
14 15 16 17 18 19 20 |
# File 'lib/social_tokenizer/token_type.rb', line 14 def self.all results = {} ObjectSpace.each_object(self) do |token_type| results[token_type.key] = token_type.tokens end results end |
.check_all(token_string) ⇒ Object
36 37 38 39 40 |
# File 'lib/social_tokenizer/token_type.rb', line 36 def self.check_all(token_string) ObjectSpace.each_object(self) do |token_type| token_type.check_token(token_string) end end |
Instance Method Details
#check_token(token_string) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/social_tokenizer/token_type.rb', line 22 def check_token(token_string) if pattern.is_a? Array for sub_pattern in pattern if token_string =~ sub_pattern self.tokens << SocialTokenizer::Token.new(token_type: self, value: token_string) end end else if token_string =~ pattern self.tokens << SocialTokenizer::Token.new(token_type: self, value: token_string) end end end |