Class: Stellar::Amount

Inherits:
Object
  • Object
show all
Includes:
Contracts
Defined in:
lib/stellar/amount.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#amountObject (readonly)

Returns the value of attribute amount.



5
6
7
# File 'lib/stellar/amount.rb', line 5

def amount
  @amount
end

#assetObject (readonly)

Returns the value of attribute asset.



6
7
8
# File 'lib/stellar/amount.rb', line 6

def asset
  @asset
end

Instance Method Details

#inspectObject



36
37
38
# File 'lib/stellar/amount.rb', line 36

def inspect
  "#<Stellar::Amount #{asset}(#{amount})>" 
end

#to_paymentObject



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