Class: Radiator::Type::Amount
- Inherits:
-
Serializer
- Object
- Serializer
- Radiator::Type::Amount
- Defined in:
- lib/radiator/type/amount.rb
Overview
Instance Method Summary collapse
-
#initialize(value) ⇒ Amount
constructor
A new instance of Amount.
- #to_bytes ⇒ Object
- #to_s ⇒ Object
Methods included from Utils
#hexlify, #pakArr, #pakC, #pakHash, #pakI, #pakL!, #pakS, #pakStr, #pakc, #paks, #unhexlify, #varint
Constructor Details
#initialize(value) ⇒ Amount
Returns a new instance of Amount.
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/radiator/type/amount.rb', line 6 def initialize(value) super(:amount, value) @amount, @asset = @value.strip.split(' ') @precision = case @asset when 'STEEM' then 3 when 'VESTS' then 6 when 'SBD' then 3 when 'GOLOS' then 3 when 'GESTS' then 6 when 'GBG' then 3 when 'CORE' then 3 when 'CESTS' then 6 when 'TEST' then 3 else; raise TypeError, "Asset #{@asset} unknown." end end |
Instance Method Details
#to_bytes ⇒ Object
24 25 26 27 28 29 30 31 |
# File 'lib/radiator/type/amount.rb', line 24 def to_bytes asset = @asset.ljust(7, "\x00") amount = (@amount.to_f * 10 ** @precision).round [amount].pack('q') + [@precision].pack('c') + asset end |
#to_s ⇒ Object
33 34 35 |
# File 'lib/radiator/type/amount.rb', line 33 def to_s "#{@amount} #{@asset}" end |