3 ################################################################################
4 # A collection of transactions.
5 ################################################################################
8 # Initializes a _Transactions_ object.
9 def initialize(filename)
12 @account_register = AccountRegister.new
16 # Synchronizes the the data store with the data store source.
17 def sync(options = {})
18 options = { :read => true, :write => true }.merge options
19 import if options[:read]
20 export if options[:write]
30 @transactions.each { |transaction| yield(transaction) }
33 # Add one or more transactions to the ledger.
34 def add(*transactions)
35 transactions.each do |transaction|
36 transaction.from.balance -= transaction.amount
37 transaction.to.balance += transaction.amount
39 @transactions.push(*transactions)
42 # Accumulate transactions corresponding to a given predicate block.
44 register = AccountRegister.new # fresh register with 0 balances
45 @transactions.each do |transaction|
46 next unless yield(transaction)
47 from = register.open(*transaction.from.path)
48 from.balance -= transaction.amount
49 to = register.open(*transaction.to.path)
50 to.balance += transaction.amount
55 # Get a collection of the accounts defined.
57 @account_register.accounts