Class: Zold::Id

Inherits:
Object
  • Object
show all
Defined in:
lib/zold/id.rb

Overview

Id of the wallet

Constant Summary collapse

ROOT =

The ID of the root wallet.

Id.new('0000000000000000')

Instance Method Summary collapse

Constructor Details

#initialize(id = format('%016x', rand(2**32..2**64 - 1))) ⇒ Id

Returns a new instance of Id.



34
35
36
37
38
# File 'lib/zold/id.rb', line 34

def initialize(id = format('%016x', rand(2**32..2**64 - 1)))
  raise "Invalid wallet ID type: #{id.class.name}" unless id.is_a?(String)
  raise "Invalid wallet ID: #{id}" unless PTN.match?(id)
  @id = Integer("0x#{id}", 16)
end

Instance Method Details

#<=>(other) ⇒ Object



61
62
63
64
# File 'lib/zold/id.rb', line 61

def <=>(other)
  raise 'Can only compare with Id' unless other.is_a?(Id)
  to_s <=> other.to_s
end

#==(other) ⇒ Object



56
57
58
59
# File 'lib/zold/id.rb', line 56

def ==(other)
  raise 'Can only compare with Id' unless other.is_a?(Id)
  to_s == other.to_s
end

#eql?(other) ⇒ Boolean

Returns:

  • (Boolean)


47
48
49
50
# File 'lib/zold/id.rb', line 47

def eql?(other)
  raise 'Can only compare with Id' unless other.is_a?(Id)
  to_s == other.to_s
end

#hashObject



52
53
54
# File 'lib/zold/id.rb', line 52

def hash
  to_s.hash
end

#root?Boolean

Returns:

  • (Boolean)


43
44
45
# File 'lib/zold/id.rb', line 43

def root?
  to_s == ROOT.to_s
end

#to_sObject



70
71
72
# File 'lib/zold/id.rb', line 70

def to_s
  format('%016x', @id)
end

#to_strObject



66
67
68
# File 'lib/zold/id.rb', line 66

def to_str
  to_s
end