Class: RippleRest::Amount

Inherits:
RestObject show all
Defined in:
lib/ripple-rest/generated-schemas.rb,
lib/ripple-rest/schemas.rb,
lib/ripple-rest/generated-schemas.rb

Overview

An Amount on the Ripple Protocol, used also for XRP in the ripple-rest API

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from RestObject

#initialize, #to_hash

Constructor Details

This class inherits a constructor from RippleRest::RestObject

Instance Attribute Details

#counterpartyString

The Ripple account address of the currency's issuer or gateway, or an empty string if the currency is XRP

Returns:

  • (String)

    “^$|^r{25,33}$”


387
# File 'lib/ripple-rest/generated-schemas.rb', line 387

property :counterparty, [:String, "^$|^r[1-9A-HJ-NP-Za-km-z]{25,33}$"]

#currencyString<Currency>

The currency expressed as a three-character code

Returns:

  • (String<Currency>)

376
# File 'lib/ripple-rest/generated-schemas.rb', line 376

property :currency, :Currency

#issuerString

The Ripple account address of the currency's issuer or gateway, or an empty string if the currency is XRP

Returns:

  • (String)

    “^$|^r{25,33}$”


382
# File 'lib/ripple-rest/generated-schemas.rb', line 382

property :issuer, [:String, "^$|^r[1-9A-HJ-NP-Za-km-z]{25,33}$"]

#valueString

The quantity of the currency, denoted as a string to retain floating point precision

Returns:

  • (String)

370
# File 'lib/ripple-rest/generated-schemas.rb', line 370

property :value, :String

Class Method Details

.from_string(s) ⇒ Amount

Parameters:

  • s (String, Amount)

    an Amount object or a String like “1+XRP” or “1+USD+r…”

Returns:


32
33
34
35
36
37
38
39
40
41
# File 'lib/ripple-rest/schemas.rb', line 32

def self.from_string s
  return s if s.is_a?(Amount)
  
  arr = s.split("+")
  Amount.new({
    "value" => arr[0],
    "currency" => arr[1],
    "issuer" => arr[2]
  })
end

Instance Method Details

#to_sString

Returns:

  • (String)

26
27
28
# File 'lib/ripple-rest/schemas.rb', line 26

def to_s
  "#{value}+#{currency}#{issuer.to_s.size > 0 ? ("+" + issuer) : ""}"
end