forked from babyname/fate
-
Notifications
You must be signed in to change notification settings - Fork 0
/
name.go
80 lines (70 loc) · 1.42 KB
/
name.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
72
73
74
75
76
77
78
79
80
package fate
import (
"github.com/godcong/chronos"
"github.com/godcong/yi"
"strings"
)
//Name 姓名
type Name struct {
FirstName []*Character //名姓
LastName []*Character
born *chronos.Calendar
baGua *yi.Yi //周易八卦
zodiac *Zodiac
zodiacPoint int
}
func (n Name) String() string {
var s string
for _, l := range n.LastName {
s += l.Ch
}
for _, f := range n.FirstName {
s += f.Ch
}
return s
}
func (n Name) PinYin() string {
var s string
for _, l := range n.LastName {
s += "[" + strings.Join(l.PinYin, ",") + "]"
}
for _, f := range n.FirstName {
s += "[" + strings.Join(f.PinYin, ",") + "]"
}
return s
}
func (n Name) WuXing() string {
var s string
for _, l := range n.LastName {
s += l.WuXing
}
for _, f := range n.FirstName {
s += f.WuXing
}
return s
}
func createName(impl *fateImpl, f1 *Character, f2 *Character) *Name {
lastSize := len(impl.lastChar)
last := make([]*Character, lastSize, lastSize)
copy(last, impl.lastChar)
ff1 := *f1
ff2 := *f2
first := []*Character{&ff1, &ff2}
return &Name{
FirstName: first,
LastName: last,
}
}
//BaGua
func (n *Name) BaGua() *yi.Yi {
if n.baGua == nil {
lastSize := len(n.LastName)
shang := getStroke(n.LastName[0])
if lastSize > 1 {
shang += getStroke(n.LastName[1])
}
xia := getStroke(n.FirstName[0]) + getStroke(n.FirstName[1])
n.baGua = yi.NumberQiGua(xia, shang, shang+xia)
}
return n.baGua
}