elliotchance / gedcom

👪 A Go library and CLI tools for encoding, decoding, traversing, merging, comparing, querying and publishing GEDCOM files.
MIT License
94 stars 21 forks source link

Adding individuals to a family should create corresponding FAMS/FAMC nodes. #309

Open jazzboME opened 4 years ago

jazzboME commented 4 years ago

I've been working on doing some simple GEDCOM file creation and I was noticing that with routines like AddFamilyWithHusbandAndWife() I wasn't ending up with FAMS nodes on the individuals. (Compare F6 at http://wiki-en.genealogy.net/GEDCOM/FAM-Tag#Agreements_for_FAM)

I'm working on a pull request to add that support initially to (node *FamilyNode) SetHusband() and (node *FamilyNode) SetWife() and I'll look at AddChild() after that.

While I'm working on this, I'm finding the need to duplicate the pattern of fmt.Sprintf("@%s@", node.Pointer()) in various places.

So a) okay if I tackle this issue with adding the FAMS/FAMC in the individual nodes?

and b) I'm wondering as part of working on this, if it is worthwhile to add another method that return a node pointer pre-formatted with the @ signs? Something like:

// Identifier returns the "@...@" identifier for the node; empty string if the node is nil
func (node *SimpleNode) Identifier() string {
    if node == nil {
        return ""
    }

    return fmt.Sprintf("@%s@", node.pointer)
}
elliotchance commented 4 years ago

I suppose adding that method would be acceptable since it's part of the standard for all nodes.

Families are tricky, so you surely have found a bug. Any patch you can submit will be appreciated. 👍