Class: Keisan::Tokens::BitwiseOperator

Inherits:
Operator show all
Defined in:
lib/keisan/tokens/bitwise_operator.rb

Constant Summary collapse

AND =
/(?:\&)/
OR =
/(?:\|)/
XOR =
/(?:\^)/
NOT =
/(?:\~+)/
REGEX =
/(#{AND}|#{OR}|#{XOR}|#{NOT})/

Instance Attribute Summary

Attributes inherited from Keisan::Token

#string

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Operator

#type

Methods inherited from Keisan::Token

#initialize, #regex, #type, type

Constructor Details

This class inherits a constructor from Keisan::Token

Class Method Details

.regexObject



11
12
13
# File 'lib/keisan/tokens/bitwise_operator.rb', line 11

def self.regex
  REGEX
end

Instance Method Details

#operator_typeObject



15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/keisan/tokens/bitwise_operator.rb', line 15

def operator_type
  case string
  when AND
    :"&"
  when OR
    :"|"
  when XOR
    :"^"
  when NOT
    string.count("~").even? ? :"~~" : :"~"
  end
end