forked from babyname/fate
-
Notifications
You must be signed in to change notification settings - Fork 0
/
name.go
108 lines (94 loc) · 1.9 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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
package fate
import (
"github.com/godcong/chronos"
"github.com/godcong/yi"
"strconv"
"strings"
)
//Name 姓名
type Name struct {
FirstName []*Character //名姓
LastName []*Character
born *chronos.Calendar
baZi *BaZi
baGua *yi.Yi //周易八卦
zodiac *Zodiac
zodiacPoint int
}
// String ...
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
}
// Strokes ...
func (n Name) Strokes() string {
var s []string
for _, l := range n.LastName {
s = append(s, strconv.Itoa(l.ScienceStroke))
}
for _, f := range n.FirstName {
s = append(s, strconv.Itoa(f.ScienceStroke))
}
return strings.Join(s, ",")
}
// PinYin ...
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
}
// WuXing ...
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
}
// XiYongShen ...
func (n Name) XiYongShen() string {
return n.baZi.XiYongShen()
}
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
}
// BaZi ...
func (n Name) BaZi() string {
return n.baZi.String()
}