Class: Coinbase::HistoricalBalance

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

Overview

A representation of an HistoricalBalance.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(amount:, block_height:, block_hash:, asset:) ⇒ HistoricalBalance

Returns a new HistoricalBalance object. Do not use this method. Instead, use Balance.from_model or Balance.from_model_and_asset_id.

Parameters:

  • amount (BigDecimal)

    The amount of the Asset

  • block_height (BigDecimal)

    The block height at which the balance was recorded

  • block_hash (String)

    The block hash at which the balance was recorded

  • asset (Asset)

    The asset we want to fetch



26
27
28
29
30
31
# File 'lib/coinbase/historical_balance.rb', line 26

def initialize(amount:, block_height:, block_hash:, asset:)
  @amount = amount
  @block_height = block_height
  @block_hash = block_hash
  @asset = asset
end

Instance Attribute Details

#amountObject (readonly)

Returns the value of attribute amount.



33
34
35
# File 'lib/coinbase/historical_balance.rb', line 33

def amount
  @amount
end

#assetObject (readonly)

Returns the value of attribute asset.



33
34
35
# File 'lib/coinbase/historical_balance.rb', line 33

def asset
  @asset
end

#block_hashObject (readonly)

Returns the value of attribute block_hash.



33
34
35
# File 'lib/coinbase/historical_balance.rb', line 33

def block_hash
  @block_hash
end

#block_heightObject (readonly)

Returns the value of attribute block_height.



33
34
35
# File 'lib/coinbase/historical_balance.rb', line 33

def block_height
  @block_height
end

Class Method Details

.from_model(historical_balance_model) ⇒ HistoricalBalance

Converts a Coinbase::Client::HistoricalBalance model to a Coinbase::HistoricalBalance

Parameters:

Returns:



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

def self.from_model(historical_balance_model)
  asset = Coinbase::Asset.from_model(historical_balance_model.asset)

  new(
    amount: asset.from_atomic_amount(historical_balance_model.amount),
    block_height: BigDecimal(historical_balance_model.block_height),
    block_hash: historical_balance_model.block_hash,
    asset: asset
  )
end

Instance Method Details

#inspectString

Same as to_s.

Returns:

  • (String)

    a string representation of the HistoricalBalance



49
50
51
# File 'lib/coinbase/historical_balance.rb', line 49

def inspect
  to_s
end

#to_sString

Returns a string representation of the HistoricalBalance.

Returns:

  • (String)

    a string representation of the HistoricalBalance



37
38
39
40
41
42
43
44
45
# File 'lib/coinbase/historical_balance.rb', line 37

def to_s
  Coinbase.pretty_print_object(
    self.class,
    amount: amount.to_i,
    block_height: block_height.to_i,
    block_hash: block_hash,
    asset: asset
  )
end