2 Star 9 Fork 3

godcong/fate

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
name.go 1.90 KB
一键复制 编辑 原始数据 按行查看 历史
godcong 提交于 2020-02-10 16:22 . fix comment
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()
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/godcong/fate.git
git@gitee.com:godcong/fate.git
godcong
fate
fate
master

搜索帮助