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 ⇒ Object
readonly
Returns the value of attribute asset.
-
#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:, asset_id: nil) ⇒ 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:, asset_id: nil) ⇒ Balance
Returns a new Balance object. Do not use this method. Instead, use Balance.from_model or Balance.from_model_and_asset_id.
35 36 37 38 39 |
# File 'lib/coinbase/balance.rb', line 35 def initialize(amount:, asset:, asset_id: nil) @amount = amount @asset = asset @asset_id = asset_id || asset.asset_id end |
Instance Attribute Details
#amount ⇒ Object (readonly)
Returns the value of attribute amount.
41 42 43 |
# File 'lib/coinbase/balance.rb', line 41 def amount @amount end |
#asset ⇒ Object (readonly)
Returns the value of attribute asset.
41 42 43 |
# File 'lib/coinbase/balance.rb', line 41 def asset @asset end |
#asset_id ⇒ Object (readonly)
Returns the value of attribute asset_id.
41 42 43 |
# File 'lib/coinbase/balance.rb', line 41 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 = Coinbase::Asset.from_model(balance_model.asset) new(amount: asset.from_atomic_amount(balance_model.amount), asset: asset) 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 27 28 29 |
# File 'lib/coinbase/balance.rb', line 21 def self.from_model_and_asset_id(balance_model, asset_id) asset = Coinbase::Asset.from_model(balance_model.asset, asset_id: asset_id) new( amount: asset.from_atomic_amount(balance_model.amount), asset: asset, asset_id: asset_id ) end |
Instance Method Details
#inspect ⇒ String
Same as to_s.
51 52 53 |
# File 'lib/coinbase/balance.rb', line 51 def inspect to_s end |
#to_s ⇒ String
Returns a string representation of the Balance.
45 46 47 |
# File 'lib/coinbase/balance.rb', line 45 def to_s Coinbase.pretty_print_object(self.class, amount: amount.to_s('F'), asset_id: asset_id) end |