Class: MudratProjector::Transaction
- Inherits:
-
Object
- Object
- MudratProjector::Transaction
- Includes:
- Enumerable
- Defined in:
- lib/mudrat_projector/transaction.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#credits ⇒ Object
Returns the value of attribute credits.
-
#date ⇒ Object
readonly
Returns the value of attribute date.
-
#debits ⇒ Object
Returns the value of attribute debits.
Instance Method Summary collapse
- #balanced? ⇒ Boolean
- #each(&block) ⇒ Object
-
#initialize(params = {}) ⇒ Transaction
constructor
A new instance of Transaction.
- #slice(slice_date) ⇒ Object
Constructor Details
#initialize(params = {}) ⇒ Transaction
Returns a new instance of Transaction.
7 8 9 10 11 |
# File 'lib/mudrat_projector/transaction.rb', line 7 def initialize params = {} @date = params.fetch :date self.credits = extract_entry_params :credit, params self.debits = extract_entry_params :debit, params end |
Instance Attribute Details
#credits ⇒ Object
Returns the value of attribute credits.
5 6 7 |
# File 'lib/mudrat_projector/transaction.rb', line 5 def credits @credits end |
#date ⇒ Object (readonly)
Returns the value of attribute date.
5 6 7 |
# File 'lib/mudrat_projector/transaction.rb', line 5 def date @date end |
#debits ⇒ Object
Returns the value of attribute debits.
5 6 7 |
# File 'lib/mudrat_projector/transaction.rb', line 5 def debits @debits end |
Instance Method Details
#balanced? ⇒ Boolean
13 14 15 16 17 |
# File 'lib/mudrat_projector/transaction.rb', line 13 def balanced? sum_credits = build_set_for_balance credits sum_debits = build_set_for_balance debits (sum_credits ^ sum_debits).empty? end |
#each(&block) ⇒ Object
27 28 29 30 |
# File 'lib/mudrat_projector/transaction.rb', line 27 def each &block credits.each &block debits.each &block end |
#slice(slice_date) ⇒ Object
32 33 34 35 36 37 38 |
# File 'lib/mudrat_projector/transaction.rb', line 32 def slice slice_date if date > slice_date [[], self] else [[self], nil] end end |