Class: Coinbase::BalanceMap
- Inherits:
- 
      Hash
      
        - Object
- Hash
- Coinbase::BalanceMap
 
- Defined in:
- lib/coinbase/balance_map.rb
Overview
A convenience class for printing out Asset balances in a human-readable format.
Class Method Summary collapse
- 
  
    
      .from_balances(balances)  ⇒ BalanceMap 
    
    
  
  
  
  
  
  
  
  
  
    Converts a list of Coinbase::Client::Balance models to a Coinbase::BalanceMap. 
Instance Method Summary collapse
- 
  
    
      #add(balance)  ⇒ Object 
    
    
  
  
  
  
  
  
  
  
  
    Adds a balance to the map. 
- 
  
    
      #inspect  ⇒ String 
    
    
  
  
  
  
  
  
  
  
  
    Returns a string representation of the balance map. 
- 
  
    
      #to_s  ⇒ String 
    
    
  
  
  
  
  
  
  
  
  
    Returns a string representation of the balance map. 
Class Method Details
.from_balances(balances) ⇒ BalanceMap
Converts a list of Coinbase::Client::Balance models to a Coinbase::BalanceMap.
| 11 12 13 14 15 16 17 18 19 | # File 'lib/coinbase/balance_map.rb', line 11 def self.from_balances(balances) BalanceMap.new.tap do |balance_map| balances.each do |balance_model| balance = Coinbase::Balance.from_model(balance_model) balance_map.add(balance) end end end | 
Instance Method Details
#add(balance) ⇒ Object
Adds a balance to the map.
| 23 24 25 26 27 | # File 'lib/coinbase/balance_map.rb', line 23 def add(balance) raise ArgumentError, 'balance must be a Coinbase::Balance' unless balance.is_a?(Coinbase::Balance) self[balance.asset_id] = balance.amount end | 
#inspect ⇒ String
Returns a string representation of the balance map.
| 37 38 39 | # File 'lib/coinbase/balance_map.rb', line 37 def inspect to_string end | 
#to_s ⇒ String
Returns a string representation of the balance map.
| 31 32 33 | # File 'lib/coinbase/balance_map.rb', line 31 def to_s to_string end |