Class: Stellar::Amount

Inherits:
Object
  • Object
show all
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.

Parameters:

  • amount (Fixnum)
  • asset (Stellar::Asset) (defaults to: Stellar::Asset.native)


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

#amountObject (readonly)

Returns the value of attribute amount.



3
4
5
# File 'lib/stellar/amount.rb', line 3

def amount
  @amount
end

#assetObject (readonly)

Returns the value of attribute asset.



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

def asset
  @asset
end

Instance Method Details

#inspectObject



32
33
34
# File 'lib/stellar/amount.rb', line 32

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

#to_paymentArray(Symbol, Fixnum), Array(Symbol, String, Stellar::KeyPair, Fixnum)

Returns:

  • (Array(Symbol, Fixnum))

    in case of a native asset

  • (Array(Symbol, String, Stellar::KeyPair, Fixnum))

    in case of alphanum asset



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