Class: Stellar::Amount
- Inherits:
-
Object
- Object
- Stellar::Amount
- 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 ⇒ Array(Symbol, Fixnum), Array(Symbol, String, Stellar::KeyPair, Fixnum)
Constructor Details
#initialize(amount, asset = Stellar::Asset.native) ⇒ Amount
Returns a new instance of Amount.
8 9 10 11 12 13 |
# File 'lib/stellar/amount.rb', line 8 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.
3 4 5 |
# File 'lib/stellar/amount.rb', line 3 def amount @amount end |
#asset ⇒ Object (readonly)
Returns the value of attribute asset.
4 5 6 |
# File 'lib/stellar/amount.rb', line 4 def asset @asset end |
Instance Method Details
#inspect ⇒ Object
32 33 34 |
# File 'lib/stellar/amount.rb', line 32 def inspect "#<Stellar::Amount #{asset}(#{amount})>" end |
#to_payment ⇒ Array(Symbol, Fixnum), Array(Symbol, String, Stellar::KeyPair, Fixnum)
17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/stellar/amount.rb', line 17 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 |