Example #1
0
func loadDatabase(path string, f func(t ...*transaction.Transaction)) {
	file := openFile(path)

	reader := transaction.NewReader(file)
	for {
		t, err := reader.Next()
		if err != nil {
			fatalErr(err)
		}
		if t == nil {
			break
		}
		f(t)
	}
}
Example #2
0
func readTransactions(fileName string) []*transaction.Transaction {
	file := openFile(fileName)
	defer file.Close()
	reader := transaction.NewReader(file)
	var results []*transaction.Transaction
	for {
		t, err := reader.Next()
		if err != nil {
			fatalErr(err)
		}

		if t == nil {
			break
		}
		results = append(results, t)
	}
	return results
}
Example #3
0
var _ = Describe("Reader", func() {

	var reader *transaction.Reader

	BeforeEach(func() {
		strReader := strings.NewReader(`
2015/10/12 Exxon
		Expenses:Auto:Gas         $10.00
		Liabilities:MasterCard   $-10.00
    

2015/10/12 Qdoba
		Expenses:Food:FastFood $21.50
		Liabilities:AmericanExpress $-21.50
`)
		reader = transaction.NewReader(strReader)
	})

	It("reads all the transactions", func() {
		t1, err := reader.Next()
		Expect(err).ToNot(HaveOccurred())
		t2, err := reader.Next()
		Expect(err).ToNot(HaveOccurred())

		Expect(t1).To(Equal(
			&transaction.Transaction{
				Date: transaction.NewDate(2015, 10, 12),
				Title: &transaction.Title{
					Value: "Exxon",
				},
				Accounts: &transaction.AccountList{