ana-ledger/ledger/delta.go

41 lines
740 B
Go

package ledger
import "fmt"
type Currency string
const (
USD = Currency("$")
)
type Delta struct {
Date string
Name string
Value float64
Currency Currency
Description string
}
func newDelta(d, desc, name string, v float64, c string) Delta {
return Delta{
Date: d,
Name: name,
Value: v,
Currency: Currency(c),
Description: desc,
}
}
func (delta Delta) Plus(other Delta) Delta {
return Delta{
Date: other.Date,
Name: delta.Name,
Value: delta.Value + other.Value,
Currency: other.Currency,
}
}
func (delta Delta) Debug() string {
return fmt.Sprintf("{@%s %s:\"%s\" %.2f %s}", delta.Date, delta.Name, delta.Description, delta.Value, delta.Currency)
}