Class: SocialTokenizer::TokenType

Inherits:
Object
  • Object
show all
Includes:
ActiveModel::Model, ActiveModel::Validations
Defined in:
lib/social_tokenizer/token_type.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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

#formatterObject

Returns the value of attribute formatter


6
7
8
# File 'lib/social_tokenizer/token_type.rb', line 6

def formatter
  @formatter
end

#keyObject

Returns the value of attribute key


6
7
8
# File 'lib/social_tokenizer/token_type.rb', line 6

def key
  @key
end

#patternObject

Returns the value of attribute pattern


6
7
8
# File 'lib/social_tokenizer/token_type.rb', line 6

def pattern
  @pattern
end

#replacementObject

Returns the value of attribute replacement


6
7
8
# File 'lib/social_tokenizer/token_type.rb', line 6

def replacement
  @replacement
end

#tokensObject

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

.allObject


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