Class: EthereumContractABI::ContractInterface::AbiTypes::Int
- Inherits:
-
BaseType
- Object
- BaseType
- EthereumContractABI::ContractInterface::AbiTypes::Int
show all
- Defined in:
- lib/ethereum-contract-abi/contract/abi_types/int.rb
Direct Known Subclasses
Uint
Class Method Summary
collapse
Instance Method Summary
collapse
Methods inherited from BaseType
#bytesize, #is_type_equal
Constructor Details
#initialize(bits = 256) ⇒ Int
Returns a new instance of Int.
12
13
14
15
|
# File 'lib/ethereum-contract-abi/contract/abi_types/int.rb', line 12
def initialize(bits = 256)
raise ArgumentError.new("8 must be a factor of bits") unless bits % 8 === 0
@bits = bits
end
|
Class Method Details
.from_string(string_type) ⇒ Object
40
41
42
43
44
|
# File 'lib/ethereum-contract-abi/contract/abi_types/int.rb', line 40
def self.from_string(string_type)
/(?<is_int>^int)(?<bits>\d+)?/ =~ string_type
return nil unless is_int
bits ? self.new(bits.to_i) : self.new
end
|
Instance Method Details
#decode_value(value) ⇒ Object
36
37
38
|
# File 'lib/ethereum-contract-abi/contract/abi_types/int.rb', line 36
def decode_value(value)
IntDecoder.decode(value)
end
|
#encode_value(number) ⇒ Object
31
32
33
34
|
# File 'lib/ethereum-contract-abi/contract/abi_types/int.rb', line 31
def encode_value(number)
raise ArgumentError unless valid_value?(number)
IntEncoder.encode(number)
end
|
#is_dynamic ⇒ Object
17
18
19
|
# File 'lib/ethereum-contract-abi/contract/abi_types/int.rb', line 17
def is_dynamic
false
end
|
#to_s ⇒ Object
21
22
23
|
# File 'lib/ethereum-contract-abi/contract/abi_types/int.rb', line 21
def to_s
"int#{@bits}"
end
|
#valid_value?(number) ⇒ Boolean
25
26
27
28
29
|
# File 'lib/ethereum-contract-abi/contract/abi_types/int.rb', line 25
def valid_value?(number)
return false unless number.is_a? Numeric
return false unless number.bit_length <= @bits
true
end
|