Class: Stellar::Amount
- Inherits:
-
Object
- Object
- Stellar::Amount
- Includes:
- Contracts
- Defined in:
- lib/stellar/amount.rb
Instance Attribute Summary collapse
-
#amount ⇒ Object
readonly
Returns the value of attribute amount.
-
#asset ⇒ Object
readonly
Returns the value of attribute asset.
Instance Method Summary collapse
-
#initialize(amount, asset = Stellar::Asset.native()) ⇒ Amount
constructor
A new instance of Amount.
- #inspect ⇒ Object
- #to_payment ⇒ Object
Constructor Details
#initialize(amount, asset = Stellar::Asset.native()) ⇒ Amount
Returns a new instance of Amount.
9 10 11 12 13 14 |
# File 'lib/stellar/amount.rb', line 9 def initialize(amount, asset=Stellar::Asset.native()) # TODO: how are we going to handle decimal considerations? @amount = amount @asset = asset end |
Instance Attribute Details
#amount ⇒ Object (readonly)
Returns the value of attribute amount.
5 6 7 |
# File 'lib/stellar/amount.rb', line 5 def amount @amount end |
#asset ⇒ Object (readonly)
Returns the value of attribute asset.
6 7 8 |
# File 'lib/stellar/amount.rb', line 6 def asset @asset end |
Instance Method Details
#inspect ⇒ Object
36 37 38 |
# File 'lib/stellar/amount.rb', line 36 def inspect "#<Stellar::Amount #{asset}(#{amount})>" end |
#to_payment ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/stellar/amount.rb', line 21 def to_payment case asset.type when AssetType.asset_type_native [:native, amount] when AssetType.asset_type_credit_alphanum4 keypair = KeyPair.from_public_key(asset.issuer.value) [:alphanum4, asset.code, keypair, amount] when AssetType.asset_type_credit_alphanum12 keypair = KeyPair.from_public_key(asset.issuer.value) [:alphanum12, asset.code, keypair, amount] else raise "Unknown asset type: #{asset.type}" end end |