-
Notifications
You must be signed in to change notification settings - Fork 11
/
tablib_databook.go
54 lines (44 loc) · 1.19 KB
/
tablib_databook.go
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
package tablib
// Sheet represents a sheet in a Databook, holding a title (if any) and a dataset.
type Sheet struct {
title string
dataset *Dataset
}
// Title return the title of the sheet.
func (s Sheet) Title() string {
return s.title
}
// Dataset returns the dataset of the sheet.
func (s Sheet) Dataset() *Dataset {
return s.dataset
}
// Databook represents a Databook which is an array of sheets.
type Databook struct {
sheets map[string]Sheet
}
// NewDatabook constructs a new Databook.
func NewDatabook() *Databook {
return &Databook{make(map[string]Sheet)}
}
// Sheets returns the sheets in the Databook.
func (d *Databook) Sheets() map[string]Sheet {
return d.sheets
}
// Sheet returns the sheet with a specific title.
func (d *Databook) Sheet(title string) Sheet {
return d.sheets[title]
}
// AddSheet adds a sheet to the Databook.
func (d *Databook) AddSheet(title string, dataset *Dataset) {
d.sheets[title] = Sheet{title, dataset}
}
// Size returns the number of sheets in the Databook.
func (d *Databook) Size() int {
return len(d.sheets)
}
// Wipe removes all Dataset objects from the Databook.
func (d *Databook) Wipe() {
for k := range d.sheets {
delete(d.sheets, k)
}
}