Class: Coinbase::FiatAmount
- Inherits:
-
Object
- Object
- Coinbase::FiatAmount
- Defined in:
- lib/coinbase/fiat_amount.rb
Overview
A representation of a FiatAmount that includes the amount and fiat.
Instance Attribute Summary collapse
-
#amount ⇒ Object
readonly
Returns the value of attribute amount.
-
#currency ⇒ Object
readonly
Returns the value of attribute currency.
Class Method Summary collapse
-
.from_model(model) ⇒ FiatAmount
Converts a Coinbase::Client::FiatAmount model to a Coinbase::FiatAmount.
Instance Method Summary collapse
-
#initialize(amount:, currency:) ⇒ FiatAmount
constructor
Returns a new FiatAmount object.
-
#inspect ⇒ String
Same as to_s.
-
#to_s ⇒ String
Returns a string representation of the FiatAmount.
Constructor Details
#initialize(amount:, currency:) ⇒ FiatAmount
Returns a new FiatAmount object.
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
#amount ⇒ Object (readonly)
Returns the value of attribute amount.
26 27 28 |
# File 'lib/coinbase/fiat_amount.rb', line 26 def amount @amount end |
#currency ⇒ Object (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
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
#inspect ⇒ String
Same as to_s.
36 37 38 |
# File 'lib/coinbase/fiat_amount.rb', line 36 def inspect to_s end |
#to_s ⇒ String
Returns 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 |