Representation of user account data.

Sections
Methods
I
M
N
T
U
Class Public methods
new(hash)
# File lib/plaid/account.rb, line 56
def initialize(hash)
  @id          = hash['_id']
  @item_id     = hash['_item']
  @meta        = hash['meta']
  @type        = hash['type'].to_sym
  @subtype     = hash['subtype']
  @institution = hash['institution_type'].to_sym

  unless (bal = hash['balance']).nil?
    @available_balance = bal['available']
    @current_balance   = bal['current']
  end

  if (risk = hash['risk'])
    @risk = Plaid::Risk.new(risk)
  end

  @numbers = Plaid.symbolize_hash(hash['numbers'])
end
Public
Attributes
[R] available_balance

The Float value of the available balance for the account.

The Available Balance is the Current Balance less any outstanding holds or debits that have not yet posted to the account. Note that not all institutions calculate the Available Balance. In the case that Available Balance is unavailable from the institution, Plaid will either return an Available Balance value of null or only return a Current Balance.

[R] current_balance

The Float value of the current balance for the account.

[R] id

The String unique ID of the account. E.g. “QPO8Jo8vdDHMepg41PBwckXm4KdK1yUdmXOwK”.

[R] institution

The Symbol institution type, e.g. :wells.

[R] item_id

The String account ID unique to the accounts of a particular access token. E.g. “KdDjmojBERUKx3JkDd9RuxA5EvejA4SENO4AA”.

[R] meta

The Hash with additional information pertaining to the account such as the limit, name, or last few digits of the account number. E.g. {“name”: “Plaid Savings”, “number”: “9606” }.

[R] numbers

The Hash with account and routing numbers for the account.

This attribute would be nil unless you used Auth product for the user.

The Hash contains Symbol keys and String values. E.g. {routing: “021000021”, account: “9900009606”, wireRouting: “021000021”}.

[R] risk

The Risk information associated with the account.

This attribute would be nil unless you used Risk product for the user.

[R] subtype

The String account subtype. E.g. “savings”.

Read more about subtypes in the Plaid API docs.

[R] type

The Symbol account type. One of :depository, :credit, :loan, :mortgage, :brokerage, and :other.

Instance Public methods
inspect()

Get a String representation of the account.

Returns

Returns a String.

Also aliased as: to_s
# File lib/plaid/account.rb, line 79
def inspect
  "#<Plaid::Account id=#{id.inspect}, type=#{type.inspect}, "        "name=#{name.inspect}, institution=#{institution.inspect}>"
end
name()

Get the account name.

The name is obtained from meta Hash.

Returns

Returns the String name.

# File lib/plaid/account.rb, line 94
def name
  meta && meta['name']
end
to_s()

Get a String representation of the account.

Returns

Returns a String.

Alias for: inspect
Internal
Class Public methods
merge(accounts, new_accounts)

Merge account information.

accounts

The Array of Account instances.

new_accounts

The Array of Account instances.

Returns

Returns accounts.

# File lib/plaid/account.rb, line 104
def self.merge(accounts, new_accounts)
  # Index accounts by their ID.
  #
  # Same as index = accounts.index_by(&:id) in ActiveSupport.
  index = Hash[accounts.map { |a| [a.id, a] }]

  new_accounts.each do |acc|
    if (old_acc = index[acc.id])
      old_acc.update_from(acc)
    else
      accounts << acc
    end
  end

  accounts
end
Instance Public methods
update_from(another)

Update account information.

All fields which are not nil in another are copied to self.

another

The Account instance with new information.

Returns

Returns self.

# File lib/plaid/account.rb, line 128
def update_from(another)
  # A sanity check. Nobody would want to update information from totally
  # different account!
  if id != another.id
    raise ArgumentError, 'Plaid::Account#update_from: id != another.id!'
  end

  %(item_id meta name type subtype institution available_balance
     current_balance numbers risk).each do |field|
    value = another.send(field)
    instance_variable_set("@#{field}", value) unless value.nil?
  end

  self
end