Class: Keisan::Tokens::Group

Inherits:
Keisan::Token show all
Defined in:
lib/keisan/tokens/group.rb

Constant Summary collapse

REGEX =
/(\((?:[^\[\]\(\)\{\}]*+\g<1>*+)*+\)|\[(?:[^\[\]\(\)\{\}]*+\g<1>*+)*+\]|\{(?:[^\[\]\(\)\{\}]*+\g<1>*+)*+\})/

Instance Attribute Summary collapse

Attributes inherited from Keisan::Token

#string

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Keisan::Token

#regex, type, #type

Constructor Details

#initialize(string) ⇒ Group

Returns a new instance of Group.



8
9
10
11
# File 'lib/keisan/tokens/group.rb', line 8

def initialize(string)
  super
  @sub_tokens = Tokenizer.new(string[1...-1]).tokens
end

Instance Attribute Details

#sub_tokensObject (readonly)

Returns the value of attribute sub_tokens.



6
7
8
# File 'lib/keisan/tokens/group.rb', line 6

def sub_tokens
  @sub_tokens
end

Class Method Details

.regexObject



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

def self.regex
  REGEX
end

Instance Method Details

#group_typeObject

Either :round, :square



18
19
20
21
22
23
24
25
26
27
# File 'lib/keisan/tokens/group.rb', line 18

def group_type
  case string[0]
  when "("
    :round
  when "["
    :square
  when "{"
    :curly
  end
end