tablib_databook.go 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. package tablib
  2. // Sheet represents a sheet in a Databook, holding a title (if any) and a dataset.
  3. type Sheet struct {
  4. title string
  5. dataset *Dataset
  6. }
  7. // Title return the title of the sheet.
  8. func (s Sheet) Title() string {
  9. return s.title
  10. }
  11. // Dataset returns the dataset of the sheet.
  12. func (s Sheet) Dataset() *Dataset {
  13. return s.dataset
  14. }
  15. // Databook represents a Databook which is an array of sheets.
  16. type Databook struct {
  17. sheets map[string]Sheet
  18. }
  19. // NewDatabook constructs a new Databook.
  20. func NewDatabook() *Databook {
  21. return &Databook{make(map[string]Sheet)}
  22. }
  23. // Sheets returns the sheets in the Databook.
  24. func (d *Databook) Sheets() map[string]Sheet {
  25. return d.sheets
  26. }
  27. // Sheet returns the sheet with a specific title.
  28. func (d *Databook) Sheet(title string) Sheet {
  29. return d.sheets[title]
  30. }
  31. // AddSheet adds a sheet to the Databook.
  32. func (d *Databook) AddSheet(title string, dataset *Dataset) {
  33. d.sheets[title] = Sheet{title, dataset}
  34. }
  35. // Size returns the number of sheets in the Databook.
  36. func (d *Databook) Size() int {
  37. return len(d.sheets)
  38. }
  39. // Wipe removes all Dataset objects from the Databook.
  40. func (d *Databook) Wipe() {
  41. for k := range d.sheets {
  42. delete(d.sheets, k)
  43. }
  44. }