Skip to content

Commit

Permalink
Merge pull request mbulat#48 from gnapse/gnapse-unless-else
Browse files Browse the repository at this point in the history
Avoid using unless-else constructs
  • Loading branch information
mbulat committed Jul 22, 2015
2 parents 5fc304f + 12f2912 commit a0730d1
Showing 1 changed file with 12 additions and 12 deletions.
24 changes: 12 additions & 12 deletions app/models/plutus/account.rb
Original file line number Diff line number Diff line change
Expand Up @@ -60,14 +60,14 @@ class Account < ActiveRecord::Base
#
# @return [BigDecimal] The decimal value balance
def balance
unless self.class == Plutus::Account
if self.class == Plutus::Account
raise(NoMethodError, "undefined method 'balance'")
else
if self.normal_credit_balance ^ contra
credits_balance - debits_balance
else
debits_balance - credits_balance
end
else
raise(NoMethodError, "undefined method 'balance'")
end
end

Expand Down Expand Up @@ -104,19 +104,19 @@ def debits_balance
#
# @return [BigDecimal] The decimal value balance
def self.balance
unless self.new.class == Plutus::Account
if self.new.class == Plutus::Account
raise(NoMethodError, "undefined method 'balance'")
else
accounts_balance = BigDecimal.new('0')
accounts = self.all
accounts.each do |account|
unless account.contra
accounts_balance += account.balance
else
if account.contra
accounts_balance -= account.balance
else
accounts_balance += account.balance
end
end
accounts_balance
else
raise(NoMethodError, "undefined method 'balance'")
end
end

Expand All @@ -129,10 +129,10 @@ def self.balance
#
# @return [BigDecimal] The decimal value balance of all accounts
def self.trial_balance
unless self.new.class == Plutus::Account
raise(NoMethodError, "undefined method 'trial_balance'")
else
if self.new.class == Plutus::Account
Plutus::Asset.balance - (Plutus::Liability.balance + Plutus::Equity.balance + Plutus::Revenue.balance - Plutus::Expense.balance)
else
raise(NoMethodError, "undefined method 'trial_balance'")
end
end

Expand Down

0 comments on commit a0730d1

Please sign in to comment.