-
-
Notifications
You must be signed in to change notification settings - Fork 369
Expand file tree
/
Copy pathcurriculum.go
More file actions
77 lines (66 loc) · 1.63 KB
/
curriculum.go
File metadata and controls
77 lines (66 loc) · 1.63 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
package user
import (
"fmt"
"strings"
"github.com/exercism/cli/api"
)
// Status is the status of a track (active/inactive).
type Status bool
const (
// TrackActive represents an active track.
// Problems from active tracks will be delivered with the `fetch` command.
TrackActive Status = true
// TrackInactive represents an inactive track.
// It is possible to fetch problems from an inactive track, and
// submit them to the website, but these will not automatically be
// delivered in the global `fetch` command.
TrackInactive Status = false
)
// Curriculum is a collection of language tracks.
type Curriculum struct {
Tracks []*api.Track
wLang int
wID int
}
// NewCurriculum returns a collection of language tracks.
func NewCurriculum(tracks []*api.Track) *Curriculum {
return &Curriculum{Tracks: tracks}
}
// Report creates a table of the tracks that have the requested status.
func (cur *Curriculum) Report(status Status) {
for _, track := range cur.Tracks {
if Status(track.Active) == status {
fmt.Println(
" ",
track.Language,
strings.Repeat(" ", cur.lenLang()-len(track.Language)+1),
track.ID,
strings.Repeat(" ", cur.lenID()-len(track.ID)+1),
track.Len(),
"problems",
)
}
}
}
func (cur *Curriculum) lenLang() int {
if cur.wLang > 0 {
return cur.wLang
}
for _, track := range cur.Tracks {
if len(track.Language) > cur.wLang {
cur.wLang = len(track.Language)
}
}
return cur.wLang
}
func (cur *Curriculum) lenID() int {
if cur.wID > 0 {
return cur.wID
}
for _, track := range cur.Tracks {
if len(track.ID) > cur.wID {
cur.wID = len(track.ID)
}
}
return cur.wID
}