forked from adlio/trello
-
Notifications
You must be signed in to change notification settings - Fork 0
/
action-collection.go
57 lines (49 loc) · 1.51 KB
/
action-collection.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
55
56
57
package trello
import (
"sort"
)
// ActionCollection is an alias of []*Action, which sorts by the Action's ID.
// Which is the same as sorting by the Action's time of occurrence
type ActionCollection []*Action
func (c ActionCollection) Len() int { return len(c) }
func (c ActionCollection) Swap(i, j int) { c[i], c[j] = c[j], c[i] }
func (c ActionCollection) Less(i, j int) bool { return c[i].ID < c[j].ID }
func (actions ActionCollection) FirstCardCreateAction() *Action {
sort.Sort(actions)
for _, action := range actions {
if action.DidCreateCard() {
return action
}
}
return nil
}
func (actions ActionCollection) ContainsCardCreation() bool {
return actions.FirstCardCreateAction() != nil
}
func (c ActionCollection) FilterToCardCreationActions() ActionCollection {
newSlice := make(ActionCollection, 0, len(c))
for _, action := range c {
if action.DidCreateCard() {
newSlice = append(newSlice, action)
}
}
return newSlice
}
func (c ActionCollection) FilterToListChangeActions() ActionCollection {
newSlice := make(ActionCollection, 0, len(c))
for _, action := range c {
if action.DidChangeListForCard() {
newSlice = append(newSlice, action)
}
}
return newSlice
}
func (c ActionCollection) FilterToCardMembershipChangeActions() ActionCollection {
newSlice := make(ActionCollection, 0, len(c))
for _, action := range c {
if action.DidChangeCardMembership() || action.DidArchiveCard() || action.DidUnarchiveCard() {
newSlice = append(newSlice, action)
}
}
return newSlice
}