-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcommodity.go.todo
More file actions
96 lines (83 loc) · 1.69 KB
/
commodity.go.todo
File metadata and controls
96 lines (83 loc) · 1.69 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
package luca
import (
"fmt"
"io"
"time"
"github.com/drummonds/luca/internal/parser"
)
var (
// Commodities by Id
Commodities = map[string]*parser.Commodity{}
CommoditiesBySymbol = map[string]*parser.Commodity{}
)
func (c *Commodity) GetIdComment() string {
return c.IdComment
}
func (c *Commodity) GetValueDate() time.Time {
return c.ValueDate
}
func (c *Commodity) GetKnowledgeDate() *time.Time {
return c.KnowledgeDate
}
// Convert commodity to a string
func (c *Commodity) GetComments() []string {
return c.Comments
}
// Convert commodity to a string
func (c *Commodity) String() string {
return c.Id
}
func (c *Commodity) NumArguments() (count int) {
count = 0
if c.Name != "" {
count++
}
if c.SubUnit != 1 {
count++
}
return
}
/*
//
892-01-01 commodity GBP
name "Pound sterling"
sub-unit 100
*/
func (c *Commodity) ToLines() []string {
lines := make([]string, len(c.Comments)+1+c.NumArguments())
for _, comment := range c.Comments {
lines = append(lines, "// "+comment)
}
// Add the directive line
lines = append(lines, DirectiveToLine(c))
// Add argument line
s := fmt.Sprintf(" name %s", c.Name)
if c.NameComment != "" {
s = " // " + c.NameComment
}
lines = append(lines, s+"\n")
s = fmt.Sprintf(" sub-unit %d", c.SubUnit)
if c.SubUnitComment != "" {
s = " // " + c.SubUnitComment
}
lines = append(lines, s+"\n")
return lines
}
func (c *Commodity) Write(w io.Writer) error {
lines := c.ToLines()
for _, line := range lines {
_, err := io.WriteString(w, line)
if err != nil {
return err
}
}
return nil
}
func (c *Commodity) includedIn(list []*Commodity) bool {
for _, c2 := range list {
if c == c2 {
return true
}
}
return false
}