class Bank::Models::Account

Public Class Methods

deposit(id, amount) click to toggle source
# File lib/bank/models/account.rb, line 19
def self.deposit(id, amount)
  puts "Depositing #{amount} on account #{id}"

  if amount <= 0
    puts 'Deposit failed! Amount must be greater than 0.00'
    return false
  end

  account = self.find_by(id: id)
  account.balance = (account.balance += amount).round(2)
  account.save!
end
open(params) click to toggle source
# File lib/bank/models/account.rb, line 14
def self.open(params)
  puts "Creating a account with #{params}"
  self.create!(params)
end
transfer(from, to, amount) click to toggle source
# File lib/bank/models/account.rb, line 45
def self.transfer(from, to, amount)
  puts "Transfering #{amount} from account #{from} to account #{to}"

  if amount <= 0
    puts 'Transfer failed! Amount must be greater than 0.00'
    return false
  end

  self.deposit(to, amount)
  self.withdraw(from, amount)
end
withdraw(id, amount) click to toggle source
# File lib/bank/models/account.rb, line 32
def self.withdraw(id, amount)
  puts "Withdrawing #{amount} on account #{id}"

  if amount <= 0
    puts 'Withdraw failed! Amount must be greater than 0.00'
    return false
  end

  account = self.find_by(id: id)
  account.balance = (account.balance -= amount).round(2)
  account.save!
end