Class: Egg::Statement
- Inherits:
-
Object
- Object
- Egg::Statement
- Defined in:
- lib/egg/statement.rb
Instance Attribute Summary collapse
-
#closing_balance ⇒ Object
readonly
Returns the value of attribute closing_balance.
-
#from_date ⇒ Object
readonly
Returns the value of attribute from_date.
-
#to_date ⇒ Object
readonly
Returns the value of attribute to_date.
-
#transactions ⇒ Object
readonly
Returns the value of attribute transactions.
Instance Method Summary collapse
- #add_transaction(transaction) ⇒ Object
-
#initialize(statement_date, closing_balance, account) ⇒ Statement
constructor
A new instance of Statement.
- #method_missing(sym, *args, &blk) ⇒ Object
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, account) 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 = 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 account_method = sym.to_s[/^account_(.+)/, 1] @account.__send__(account_method, *args, &blk) else super(sym, *args, &blk) end end |
Instance Attribute Details
#closing_balance ⇒ Object (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_date ⇒ Object (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_date ⇒ Object (readonly)
Returns the value of attribute to_date.
11 12 13 |
# File 'lib/egg/statement.rb', line 11 def to_date @to_date end |
#transactions ⇒ Object (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 |