Class: Etherlite::Types::Boolean

Inherits:
Base
  • Object
show all
Defined in:
lib/etherlite/types/boolean.rb

Constant Summary collapse

TRUE =

32 bytes

'0000000000000000000000000000000000000000000000000000000000000001'.freeze
FALSE =
'0000000000000000000000000000000000000000000000000000000000000000'.freeze

Instance Method Summary collapse

Methods inherited from Base

#dynamic?, #fixed?

Instance Method Details

#decode(_connection, _value) ⇒ Object



22
23
24
# File 'lib/etherlite/types/boolean.rb', line 22

def decode(_connection, _value)
  _value.hex > 0
end

#encode(_value) ⇒ Object



14
15
16
17
18
19
20
# File 'lib/etherlite/types/boolean.rb', line 14

def encode(_value)
  unless _value.is_a?(TrueClass) || _value.is_a?(FalseClass)
    raise ArgumentError, "value must be a boolean for #{signature}"
  end

  _value ? TRUE : FALSE
end

#signatureObject



6
7
8
# File 'lib/etherlite/types/boolean.rb', line 6

def signature
  "bool"
end

#sizeObject



10
11
12
# File 'lib/etherlite/types/boolean.rb', line 10

def size
  32
end