Class: Coinbase::FiatAmount

Inherits:
Object
  • Object
show all
Defined in:
lib/coinbase/fiat_amount.rb

Overview

A representation of a FiatAmount that includes the amount and fiat.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(amount:, currency:) ⇒ FiatAmount

Returns a new FiatAmount object.

Parameters:

  • amount (BigDecimal, String)

    The amount of the Fiat Currency

  • currency (Symbol, String)

    The currency of the Fiat Amount



21
22
23
24
# File 'lib/coinbase/fiat_amount.rb', line 21

def initialize(amount:, currency:)
  @amount = BigDecimal(amount)
  @currency = Coinbase.to_sym(currency)
end

Instance Attribute Details

#amountObject (readonly)

Returns the value of attribute amount.



26
27
28
# File 'lib/coinbase/fiat_amount.rb', line 26

def amount
  @amount
end

#currencyObject (readonly)

Returns the value of attribute currency.



26
27
28
# File 'lib/coinbase/fiat_amount.rb', line 26

def currency
  @currency
end

Class Method Details

.from_model(model) ⇒ FiatAmount

Converts a Coinbase::Client::FiatAmount model to a Coinbase::FiatAmount

Parameters:

Returns:

  • (FiatAmount)

    The converted FiatAmount object.



9
10
11
12
13
14
15
16
# File 'lib/coinbase/fiat_amount.rb', line 9

def self.from_model(model)
  unless model.is_a?(Coinbase::Client::FiatAmount)
    raise ArgumentError,
          'model must be a Coinbase::Client::FiatAmount'
  end

  new(amount: model.amount, currency: model.currency)
end

Instance Method Details

#inspectString

Same as to_s.

Returns:

  • (String)

    a string representation of the FiatAmount



36
37
38
# File 'lib/coinbase/fiat_amount.rb', line 36

def inspect
  to_s
end

#to_sString

Returns a string representation of the FiatAmount.

Returns:

  • (String)

    a string representation of the FiatAmount



30
31
32
# File 'lib/coinbase/fiat_amount.rb', line 30

def to_s
  Coinbase.pretty_print_object(self.class, amount: amount.to_s('F'), currency: currency)
end