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.



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

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



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

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

.typeObject



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

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

Instance Method Details

#regexObject



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

def regex
  self.class.regex
end

#typeObject



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

def type
  self.class.type
end