Class: Spellchecker::Tokenizer::Token
- Inherits:
-
Object
- Object
- Spellchecker::Tokenizer::Token
- Defined in:
- lib/spellchecker/tokenizer/token.rb
Instance Attribute Summary collapse
- #next ⇒ Spellchecker::Tokenizer::Token
-
#position ⇒ Object
Returns the value of attribute position.
- #prev ⇒ Spellchecker::Tokenizer::Token
-
#text ⇒ Object
Returns the value of attribute text.
Instance Method Summary collapse
- #capital? ⇒ Boolean
- #digit? ⇒ Boolean
- #dot? ⇒ Boolean
- #downcased ⇒ String
- #empty? ⇒ Boolean
-
#initialize(text, position = 0) ⇒ Token
constructor
A new instance of Token.
- #inspect ⇒ String
- #normalized ⇒ String
- #word? ⇒ Boolean
Constructor Details
#initialize(text, position = 0) ⇒ Token
Returns a new instance of Token.
11 12 13 14 |
# File 'lib/spellchecker/tokenizer/token.rb', line 11 def initialize(text, position = 0) @text = text @position = position end |
Instance Attribute Details
#next ⇒ Spellchecker::Tokenizer::Token
17 18 19 |
# File 'lib/spellchecker/tokenizer/token.rb', line 17 def next @next || Tokenizer::NULL_TOKEN end |
#position ⇒ Object
Returns the value of attribute position.
6 7 8 |
# File 'lib/spellchecker/tokenizer/token.rb', line 6 def position @position end |
#prev ⇒ Spellchecker::Tokenizer::Token
22 23 24 |
# File 'lib/spellchecker/tokenizer/token.rb', line 22 def prev @prev || Tokenizer::NULL_TOKEN end |
#text ⇒ Object
Returns the value of attribute text.
6 7 8 |
# File 'lib/spellchecker/tokenizer/token.rb', line 6 def text @text end |
Instance Method Details
#capital? ⇒ Boolean
42 43 44 |
# File 'lib/spellchecker/tokenizer/token.rb', line 42 def capital? @capital ||= text.match?(/\A[A-Z]/) end |
#digit? ⇒ Boolean
52 53 54 |
# File 'lib/spellchecker/tokenizer/token.rb', line 52 def digit? @digit ||= text.match?(/\A\d+\z/) end |
#dot? ⇒ Boolean
57 58 59 |
# File 'lib/spellchecker/tokenizer/token.rb', line 57 def dot? @dot ||= text == Tokenizer::DOT end |
#downcased ⇒ String
62 63 64 |
# File 'lib/spellchecker/tokenizer/token.rb', line 62 def downcased @downcased ||= text.downcase end |
#empty? ⇒ Boolean
27 28 29 |
# File 'lib/spellchecker/tokenizer/token.rb', line 27 def empty? self == Tokenizer::NULL_TOKEN end |
#inspect ⇒ String
32 33 34 |
# File 'lib/spellchecker/tokenizer/token.rb', line 32 def inspect "#<#{self.class} (#{text.inspect}, #{position})>" end |
#normalized ⇒ String
37 38 39 |
# File 'lib/spellchecker/tokenizer/token.rb', line 37 def normalized @normalized ||= Utils.replace_quote(downcased) end |
#word? ⇒ Boolean
47 48 49 |
# File 'lib/spellchecker/tokenizer/token.rb', line 47 def word? @word ||= text.length > 1 || text.match?(/\w/) end |