elliotchance/gedcom

View on GitHub
child_node.go

Summary

Maintainability
A
0 mins
Test Coverage
package gedcom

// ChildNode is the natural, adopted, or sealed (LDS) child of a father and a
// mother.
type ChildNode struct {
    *SimpleNode
    family *FamilyNode
}

func newChildNode(family *FamilyNode, value string, children ...Node) *ChildNode {
    return &ChildNode{
        newSimpleNode(TagChild, value, "", children...),
        family,
    }
}

func newChildNodeWithIndividual(family *FamilyNode, individual *IndividualNode) *ChildNode {
    // TODO: check individual belongs to the same document as family

    famChild := NewNode(TagFamilyChild, family.Identifier(), "")
    individual.AddNode(famChild)
    
    return newChildNode(family, individual.Identifier())
}

func (node *ChildNode) Family() *FamilyNode {
    return node.family
}

func (node *ChildNode) Individual() *IndividualNode {
    if node == nil {
        return nil
    }

    n := node.family.document.NodeByPointer(valueToPointer(node.value))

    if IsNil(n) {
        return nil
    }

    return n.(*IndividualNode)
}

func (node *ChildNode) Father() *HusbandNode {
    return node.family.Husband()
}

func (node *ChildNode) Mother() *WifeNode {
    return node.family.Wife()
}

func (node *ChildNode) String() string {
    return node.Individual().String()
}