Class: Raingrams::Tokens::Token

Inherits:
Object
  • Object
show all
Defined in:
lib/raingrams/tokens/token.rb

Direct Known Subclasses

StartSentence, StopSentence, Unknown

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(gram) ⇒ Token

Creates a new Token object with the specified gram.



11
12
13
# File 'lib/raingrams/tokens/token.rb', line 11

def initialize(gram)
  @gram = gram
end

Instance Attribute Details

#gramObject (readonly)

Gram form of the token



6
7
8
# File 'lib/raingrams/tokens/token.rb', line 6

def gram
  @gram
end

Instance Method Details

#*(length) ⇒ Object

Creates an Array of the specified length containing the token.



22
23
24
# File 'lib/raingrams/tokens/token.rb', line 22

def *(length)
  [self] * length
end

#eql?(other) ⇒ Boolean Also known as: ==

Returns true if the token has the same gram as the other token, returns false otherwise.

Returns:

  • (Boolean)


30
31
32
33
34
35
36
# File 'lib/raingrams/tokens/token.rb', line 30

def eql?(other)
  if other.kind_of?(Token)
    return (@gram == other.gram)
  end

  return false
end

#inspectObject

Returns the String form of the token.



57
58
59
# File 'lib/raingrams/tokens/token.rb', line 57

def inspect
  @gram.to_s
end

#to_gramObject



15
16
17
# File 'lib/raingrams/tokens/token.rb', line 15

def to_gram
  self
end

#to_sObject

Returns the String form of the token.



43
44
45
# File 'lib/raingrams/tokens/token.rb', line 43

def to_s
  @gram.to_s
end

#to_symObject

Returns the Symbol form of the token.



50
51
52
# File 'lib/raingrams/tokens/token.rb', line 50

def to_sym
  @gram.to_sym
end