/
io.go
71 lines (58 loc) · 1.12 KB
/
io.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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
package fate
import (
"time"
"github.com/babyname/fate/cache"
"github.com/babyname/fate/ent"
)
type Sex int //girl:0,boy:1
type Input struct {
Last [2]string
Born time.Time
Sex Sex
output *Output
}
func (i *Input) Output() *Output {
if i.output == nil {
b := parseNameBasicFromInput(i)
i.output = &Output{
basic: b,
cache: cache.NewCache(),
name: make(chan FirstName, 128),
}
}
return i.output
}
type Output struct {
basic *BasicInfo
cache cache.FilterCache
name chan FirstName
}
func (o *Output) Basic() *BasicInfo {
return o.basic
}
func (o *Output) SetLastName(ln [2]*ent.Character) {
o.basic.LastName = ln
}
func (o *Output) ResetNextName() {
o.cache.SetCount(0)
}
func (o *Output) NextName() (Name, bool) {
fn, ok := o.cache.Next()
if ok {
return Name{
BasicInfo: o.basic,
FirstName: fn,
}, true
}
return Name{}, false
}
// Filter 过滤文字
func (o *Output) Filter(s string) int {
return len(o.cache.Filter(s))
}
func (o *Output) Total() int {
return o.cache.Len()
}
func (o *Output) SetCacheFilter(filterCache *cache.PutFilter) {
o.cache.SetFilter(filterCache)
}