Class: Keisan::Token

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(string) ⇒ Token

Returns a new instance of Token.



5
6
7
8
# File 'lib/keisan/token.rb', line 5

def initialize(string)
  raise Exceptions::InvalidToken.new(string) unless string.match(regex)
  @string = string
end

Instance Attribute Details

#stringObject (readonly)

Returns the value of attribute string.



3
4
5
# File 'lib/keisan/token.rb', line 3

def string
  @string
end

Class Method Details

.regexObject



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

def self.regex
  raise Exceptions::NotImplementedError.new(:regex)
end

.typeObject



14
15
16
# File 'lib/keisan/token.rb', line 14

def self.type
  @type ||= Util.underscore(self.to_s.split("::").last).to_sym
end

Instance Method Details

#regexObject



18
19
20
# File 'lib/keisan/token.rb', line 18

def regex
  self.class.regex
end

#typeObject



10
11
12
# File 'lib/keisan/token.rb', line 10

def type
  self.class.type
end