Class: Account

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
app/models/account.rb

Direct Known Subclasses

DetailAccount, SummaryAccount

Class Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Class Attribute Details

.owner_typeObject

Returns the value of attribute owner_type.



6
7
8
# File 'app/models/account.rb', line 6

def owner_type
  @owner_type
end

Class Method Details

.owned_by(klass) ⇒ Object



9
10
11
12
13
# File 'app/models/account.rb', line 9

def self.owned_by(klass)
  @owner_type = klass.to_s.classify.constantize
  belongs_to :owner, :polymorphic => true
  validate :check_owner_type
end

Instance Method Details

#balance_at(date) ⇒ Object



15
16
17
18
# File 'app/models/account.rb', line 15

def balance_at(date)
  balance = balances.where(:evaluated_at => date).first
  balance ||= Balance.new(:account => self, :evaluated_at => date)
end

#balance_before(date) ⇒ Object



20
21
22
23
# File 'app/models/account.rb', line 20

def balance_before(date)
  balances.find :first, :conditions => ["evaluated_at < ?", date],
                        :order => "evaluated_at DESC"
end

#current_balanceObject



25
26
27
# File 'app/models/account.rb', line 25

def current_balance
  balance_at(Time.now)
end