gedcom

package module
v0.0.0-...-c805616 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 12, 2017 License: MIT Imports: 4 Imported by: 0

README

gedcom

GoDoc

An implementation of GEDCOM 5.5 in Go

References

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Family

type Family struct {
	Father   *Individual
	Mother   *Individual
	Children []*Individual
}

Family represents a family record in a node structure. It can be used to traverse a Tree with a more friendly API.

type Individual

type Individual struct {
	Node     *Node
	Father   *Individual
	Mother   *Individual
	Children []*Individual
}

Individual represents an individual record in a node structure with links to other individuals.

func (*Individual) GetBirthday

func (i *Individual) GetBirthday() string

GetBirthday returns the birth date of the individual. If there is no birth date attached to the individual, an empty string is returned instead. A string is used here, as the GEDCOM format does not specify one specific format for date objects.

func (*Individual) GetName

func (i *Individual) GetName() string

GetName returns the name of the individual. If there is no name attached to the individual, an empty string is returned instead.

type Node

type Node struct {
	Depth     int
	Attribute string
	Data      string

	Parent   *Node
	Children []*Node
}

Node is a GEDCOM line, but also contains other information to help traversal and ease of use. Some examples of GEDCOM lines look like this:

0 @I1@ INDI
1 NAME John
1 SEX  M
       ^^^^^^^ Data
  ^^^^-------- Attribute
^------------- Depth

Depth will always be an integer, while Attribute and Data are basically just strings. The delimiter between the three data points is a space (" "), but Data contains the rest of the line after the second delimiter.

Depth puts the parent/child nodes into perspective. In our example above, an individual (@I1@) node is defined with two children nodes, both one node deep. While this individual node will have no parent Node, it has two children Nodes, which will both have the individual (@I1@) Node as their parent Node. Children nodes can have children nodes too. For example:

0 HEAD
1 SOUR PAF
2 NAME Personal Ancestral File
1 DATE 31 MAR 2017

In the example above, the Node structure would look like this:

&Node{ // 0xc420014230
  Depth:     0,
  Attribute: "HEAD",
  Data:      "",
  Parent:    nil,
  Children:  []*Node{
    &Node{ // 0xc4200143c0
      Depth:     1,
      Attribute: "SOUR",
      Data:      "PAF",
      Parent:    0xc420014230,
      Children:  []*Node{
        &Node{ // 0xc420014410
          Depth:     2,
          Attribute: "NAME",
          Data:      "Personal Ancestral File",
          Parent:    0xc4200143c0,
          Children:  []*Node{},
        },
      },
    },
    &Node{ // 0xc420014500
      Depth:     1,
      Attribute: "DATE",
      Data:      "31 MAR 2017",
      Parent:    0xc420014230,
      Children:  []*Node{},
    },
  },
}

A Node with a Depth of n will only ever have children with a Depth of n+1, and is not limited to any number of children.

func (*Node) GetChildNodeByAttribute

func (n *Node) GetChildNodeByAttribute(attribute string) (*Node, error)

GetChildNodeByAttribute traverses the children Nodes for an Attribute and returns the Node that the Attribute is found on.

func (*Node) GetDataByAttributes

func (n *Node) GetDataByAttributes(attributes ...string) (string, error)

GetDataByAttributes traverses the children Nodes over a list of multiple (or one) attribute(s). If there is no structure of child Nodes that has the structure requested, an empty string and an error will be returned.

The following examples assume that the individual record with the depth of 0 is the current Node.

A simple example is when we need to get the name of an individual:

0 @I1@ INDI
1 NAME John

Example:

name, err := GetDataByAttributes("NAME")
if err != nil {
  // The Node "NAME" was not found
}

Or a more complex example would be when you need to get the birth date of an individual:

0 @I1@ INDI
1 BIRT
2 DATE 15 Jun 1990

Example:

birthday, err := GetDataByAttributes("BIRT", "DATE")
if err != nil {
  // Either the Node "BIRT" or "DATE" was not found
}

type Tree

type Tree struct {
	Nodes       []*Node
	Families    []*Family
	Individuals []*Individual
}

Tree contains a node structure of a GEDCOM file.

func Parse

func Parse(lines []string) (*Tree, error)

Parse takes a slice of GEDCOM lines and converts it to a Node structure in a Tree.

func ParseFromFile

func ParseFromFile(file string) (*Tree, error)

ParseFromFile loads a file into memory and parses it to a Tree.

func (*Tree) FindIndividualByAttribute

func (t *Tree) FindIndividualByAttribute(attribute, data string) *Individual

FindIndividualByAttribute searches through the slice of Individuals on the Tree and looks for an Individual that's internal Node structure has the attribute provided with the same data provided.

func (*Tree) TraverseFamilies

func (t *Tree) TraverseFamilies() error

TraverseFamilies loops over all nodes and creates a slice of Families and a slice of Individuals.

Directories

Path Synopsis
examples

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL