Class: Spellchecker::Tokenizer::Token

Inherits:
Object
  • Object
show all
Defined in:
lib/spellchecker/tokenizer/token.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(text, position = 0) ⇒ Token

Returns a new instance of Token.

Parameters:

  • text (String)
  • position (Integer) (defaults to: 0)


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

#nextSpellchecker::Tokenizer::Token



17
18
19
# File 'lib/spellchecker/tokenizer/token.rb', line 17

def next
  @next || Tokenizer::NULL_TOKEN
end

#positionObject

Returns the value of attribute position.



6
7
8
# File 'lib/spellchecker/tokenizer/token.rb', line 6

def position
  @position
end

#prevSpellchecker::Tokenizer::Token



22
23
24
# File 'lib/spellchecker/tokenizer/token.rb', line 22

def prev
  @prev || Tokenizer::NULL_TOKEN
end

#textObject

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

Returns:

  • (Boolean)


42
43
44
# File 'lib/spellchecker/tokenizer/token.rb', line 42

def capital?
  @capital ||= text.match?(/\A[A-Z]/)
end

#digit?Boolean

Returns:

  • (Boolean)


52
53
54
# File 'lib/spellchecker/tokenizer/token.rb', line 52

def digit?
  @digit ||= text.match?(/\A\d+\z/)
end

#dot?Boolean

Returns:

  • (Boolean)


57
58
59
# File 'lib/spellchecker/tokenizer/token.rb', line 57

def dot?
  @dot ||= text == Tokenizer::DOT
end

#downcasedString

Returns:

  • (String)


62
63
64
# File 'lib/spellchecker/tokenizer/token.rb', line 62

def downcased
  @downcased ||= text.downcase
end

#empty?Boolean

Returns:

  • (Boolean)


27
28
29
# File 'lib/spellchecker/tokenizer/token.rb', line 27

def empty?
  self == Tokenizer::NULL_TOKEN
end

#inspectString

Returns:

  • (String)


32
33
34
# File 'lib/spellchecker/tokenizer/token.rb', line 32

def inspect
  "#<#{self.class} (#{text.inspect}, #{position})>"
end

#normalizedString

Returns:

  • (String)


37
38
39
# File 'lib/spellchecker/tokenizer/token.rb', line 37

def normalized
  @normalized ||= Utils.replace_quote(downcased)
end

#word?Boolean

Returns:

  • (Boolean)


47
48
49
# File 'lib/spellchecker/tokenizer/token.rb', line 47

def word?
  @word ||= text.length > 1 || text.match?(/\w/)
end