Class: Solana::Ruby::Kit::RpcTypes::Sol

Inherits:
Object
  • Object
show all
Extended by:
T::Sig
Defined in:
lib/solana/ruby/kit/rpc_types/sol.rb

Overview

SOL amounts expressed as a decimal fixed-point value with 9 decimal places. 1 SOL == 1_000_000_000 lamports, so Sol#raw is the exact Lamports count.

Mirrors TypeScript’s Sol (DecimalFixedPoint<‘unsigned’, 64, 9>).

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(raw) ⇒ Sol

Returns a new instance of Sol.



22
23
24
25
# File 'lib/solana/ruby/kit/rpc_types/sol.rb', line 22

def initialize(raw)
  @raw = T.let(raw, Integer)
  freeze
end

Instance Attribute Details

#rawObject (readonly)

Returns the value of attribute raw.



19
20
21
# File 'lib/solana/ruby/kit/rpc_types/sol.rb', line 19

def raw
  @raw
end

Instance Method Details

#==(other) ⇒ Object Also known as: eql?



42
43
44
# File 'lib/solana/ruby/kit/rpc_types/sol.rb', line 42

def ==(other)
  other.is_a?(Sol) && @raw == other.raw
end

#hashObject



47
# File 'lib/solana/ruby/kit/rpc_types/sol.rb', line 47

def hash = @raw.hash

#inspectObject



39
# File 'lib/solana/ruby/kit/rpc_types/sol.rb', line 39

def inspect = "#<#{self.class} #{self}>"

#to_sObject



29
30
31
32
33
34
35
36
# File 'lib/solana/ruby/kit/rpc_types/sol.rb', line 29

def to_s
  whole    = @raw / 10**9
  fraction = @raw % 10**9
  return whole.to_s if fraction.zero?

  frac_str = fraction.to_s.rjust(9, '0').sub(/0+\z/, '')
  "#{whole}.#{frac_str}"
end