Class: Coinbase::Balance
- Inherits:
-
Object
- Object
- Coinbase::Balance
- Defined in:
- lib/coinbase/balance.rb
Overview
A representation of an Balance.
Instance Attribute Summary collapse
-
#amount ⇒ Object
readonly
Returns the value of attribute amount.
-
#asset_id ⇒ Object
readonly
Returns the value of attribute asset_id.
Class Method Summary collapse
-
.from_model(balance_model) ⇒ Balance
Converts a Coinbase::Client::Balance model to a Coinbase::Balance.
-
.from_model_and_asset_id(balance_model, asset_id) ⇒ Balance
Converts a Coinbase::Client::Balance model and asset ID to a Coinbase::Balance This can be used to specify a non-primary denomination that we want the balance to be converted to.
Instance Method Summary collapse
-
#initialize(amount:, asset_id:) ⇒ Balance
constructor
Returns a new Balance object.
-
#inspect ⇒ String
Same as to_s.
-
#to_s ⇒ String
Returns a string representation of the Balance.
Constructor Details
#initialize(amount:, asset_id:) ⇒ Balance
Returns a new Balance object. Do not use this method. Instead, use Balance.from_model or Balance.from_model_and_asset_id.
32 33 34 35 |
# File 'lib/coinbase/balance.rb', line 32 def initialize(amount:, asset_id:) @amount = amount @asset_id = asset_id end |
Instance Attribute Details
#amount ⇒ Object (readonly)
Returns the value of attribute amount.
37 38 39 |
# File 'lib/coinbase/balance.rb', line 37 def amount @amount end |
#asset_id ⇒ Object (readonly)
Returns the value of attribute asset_id.
37 38 39 |
# File 'lib/coinbase/balance.rb', line 37 def asset_id @asset_id end |
Class Method Details
.from_model(balance_model) ⇒ Balance
Converts a Coinbase::Client::Balance model to a Coinbase::Balance
9 10 11 12 13 |
# File 'lib/coinbase/balance.rb', line 9 def self.from_model(balance_model) asset_id = Coinbase.to_sym(balance_model.asset.asset_id.downcase) from_model_and_asset_id(balance_model, asset_id) end |
.from_model_and_asset_id(balance_model, asset_id) ⇒ Balance
Converts a Coinbase::Client::Balance model and asset ID to a Coinbase::Balance This can be used to specify a non-primary denomination that we want the balance to be converted to.
21 22 23 24 25 26 |
# File 'lib/coinbase/balance.rb', line 21 def self.from_model_and_asset_id(balance_model, asset_id) new( amount: Coinbase::Asset.from_atomic_amount(BigDecimal(balance_model.amount), asset_id), asset_id: asset_id ) end |
Instance Method Details
#inspect ⇒ String
Same as to_s.
47 48 49 |
# File 'lib/coinbase/balance.rb', line 47 def inspect to_s end |
#to_s ⇒ String
Returns a string representation of the Balance.
41 42 43 |
# File 'lib/coinbase/balance.rb', line 41 def to_s "Coinbase::Balance{amount: '#{amount.to_i}', asset_id: '#{asset_id}'}" end |