Class: Beowulf::Type::Amount
- Inherits:
-
Serializer
- Object
- Serializer
- Beowulf::Type::Amount
- Defined in:
- lib/beowulf/type/amount.rb
Instance Attribute Summary collapse
-
#amount ⇒ Object
readonly
Returns the value of attribute amount.
-
#asset ⇒ Object
readonly
Returns the value of attribute asset.
-
#precision ⇒ Object
readonly
Returns the value of attribute precision.
Instance Method Summary collapse
-
#initialize(value) ⇒ Amount
constructor
A new instance of Amount.
- #to_bytes ⇒ Object
- #to_s ⇒ Object
Methods included from Utils
#debug, #error, #extract_signatures, #hexlify, #pakArr, #pakC, #pakHash, #pakI, #pakL!, #pakPubKey, #pakQ, #pakS, #pakStr, #pakc, #pakq, #paks, #send_log, #unhexlify, #varint, #warning
Constructor Details
#initialize(value) ⇒ Amount
Returns a new instance of Amount.
6 7 8 9 10 |
# File 'lib/beowulf/type/amount.rb', line 6 def initialize(value) super(:amount, value) @amount, @asset = value.strip.split(' ') @precision = 5 end |
Instance Attribute Details
#amount ⇒ Object (readonly)
Returns the value of attribute amount.
4 5 6 |
# File 'lib/beowulf/type/amount.rb', line 4 def amount @amount end |
#asset ⇒ Object (readonly)
Returns the value of attribute asset.
4 5 6 |
# File 'lib/beowulf/type/amount.rb', line 4 def asset @asset end |
#precision ⇒ Object (readonly)
Returns the value of attribute precision.
4 5 6 |
# File 'lib/beowulf/type/amount.rb', line 4 def precision @precision end |
Instance Method Details
#to_bytes ⇒ Object
12 13 14 15 16 |
# File 'lib/beowulf/type/amount.rb', line 12 def to_bytes asset = @asset.ljust(9, "\x00") amount = (@amount.to_f * 10 ** @precision).round [amount].pack('q') + [@precision].pack('L') + asset end |
#to_s ⇒ Object
18 19 20 |
# File 'lib/beowulf/type/amount.rb', line 18 def to_s "#{@amount} #{@asset}" end |