Sha256: ebdd337fed02dc157583bec6ef6711f3e8aa18544794f4b54bf9aa910e214ac2

Contents?: true

Size: 746 Bytes

Versions: 11

Compression:

Stored size: 746 Bytes

Contents

module BitWallet
  class Accounts < Array

    attr_reader :wallet
    delegate :client, to: :wallet

    def with_balance
      self.select { |account| account.balance > 0 }
    end

    def initialize(wallet)
      @wallet = wallet

      existing_accounts.each do |name|
        self.new(name)
      end
    end

    def new(name)
      if self.includes_account_name?(name)
        account = self.find {|a| a.name == name}
      else
        account = BitWallet::Account.new(wallet, name)
        self << account
      end
      account
    end

    def includes_account_name?(account_name)
      self.find {|a| a.name == account_name}.present?
    end

    private

    def existing_accounts
      client.listaccounts.keys
    end

  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
bit_wallet-0.7.2 lib/bit_wallet/accounts.rb
bit_wallet-0.7.1 lib/bit_wallet/accounts.rb
bit_wallet-0.7.0 lib/bit_wallet/accounts.rb
bit_wallet-0.6.1 lib/bit_wallet/accounts.rb
bit_wallet-0.6.0 lib/bit_wallet/accounts.rb
bit_wallet-0.5.0 lib/bit_wallet/accounts.rb
bit_wallet-0.4.0 lib/bit_wallet/accounts.rb
bit_wallet-0.3.0 lib/bit_wallet/accounts.rb
bit_wallet-0.2.0 lib/bit_wallet/accounts.rb
bit_wallet-0.1.1 lib/bit_wallet/accounts.rb
bit_wallet-0.1.0 lib/bit_wallet/accounts.rb