Class: Egg::Statement

Inherits:
Object
  • Object
show all
Defined in:
lib/egg/statement.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(statement_date, closing_balance, account) ⇒ Statement

Returns a new instance of Statement.



3
4
5
6
7
8
9
10
# File 'lib/egg/statement.rb', line 3

def initialize(statement_date, closing_balance, )
  from_date, to_date = statement_date.split(' to ')
  @from_date = Date.build(from_date)
  @to_date = Date.build(to_date)
  @closing_balance = Money.new(closing_balance).to_f
  @account = 
  @transactions = []
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(sym, *args, &blk) ⇒ Object



16
17
18
19
20
21
22
# File 'lib/egg/statement.rb', line 16

def method_missing(sym, *args, &blk)
  if  = sym.to_s[/^account_(.+)/, 1]
    @account.__send__(, *args, &blk)
  else
    super(sym, *args, &blk)
  end
end

Instance Attribute Details

#closing_balanceObject (readonly)

Returns the value of attribute closing_balance.



11
12
13
# File 'lib/egg/statement.rb', line 11

def closing_balance
  @closing_balance
end

#from_dateObject (readonly)

Returns the value of attribute from_date.



11
12
13
# File 'lib/egg/statement.rb', line 11

def from_date
  @from_date
end

#to_dateObject (readonly)

Returns the value of attribute to_date.



11
12
13
# File 'lib/egg/statement.rb', line 11

def to_date
  @to_date
end

#transactionsObject (readonly)

Returns the value of attribute transactions.



11
12
13
# File 'lib/egg/statement.rb', line 11

def transactions
  @transactions
end

Instance Method Details

#add_transaction(transaction) ⇒ Object



12
13
14
15
# File 'lib/egg/statement.rb', line 12

def add_transaction(transaction)
  transaction.date = from_date unless transaction.date
  @transactions << transaction
end