names

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

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

Go to latest
Published: Apr 14, 2017 License: MIT Imports: 6 Imported by: 0

README

Names

Go Report Card Coverage Status GoDoc Build Status

A simple package to assist with name data.


Step 0 - Installation
$ go get -u github.com/Guitarbum722/names

Get Started

Load default titles, prefixes and suffixes. Initialize with a full name, then use name fields.

package main

import (
	"fmt"

	"github.com/Guitarbum722/names"
)

func main() {
	names.LoadTitleData() // Load default titles, prefixes and suffixes
	n := names.New("Donald J. Trump")
	n.SeparateName(" ")
	fmt.Printf("First: %v : Mid: %v : Last: %v", n.First, n.Middle, n.Last)
}

...or pass a bytes.Buffer from a CSV of your choice

	if err := names.LoadTitleDataCSV(bytes.NewBuffer([]byte("Mrs.,p\nMr.,p")); err != nil {
		log.Fatal(err, " ::: Ah man, wasn't able to load your file.")
	}

Get the initials for the name.

    // include periods
    fmt.Println(n.Initials(true)) // D.J.T.

    // exclude periods
    fmt.Println(n.Initials(false)) // DJT

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Defaults = []byte(`{
    "titles": [
        {
            "title": "Mr",
            "type": "p"
        },
        {
            "title": "Mr.",
            "type": "p"
        },
        {
            "title": "Mrs",
            "type": "p"
        },
        {
            "title": "Mrs.",
            "type": "p"
        },
        {
            "title": "Ms",
            "type": "p"
        },
        {
            "title": "Ms.",
            "type": "p"
        },
        {
            "title": "Dr",
            "type": "p"
        },
        {
            "title": "Dr.",
            "type": "p"
        },
        {
            "title": "Miss",
            "type": "p"
        },
        {
            "title": "Sir",
            "type": "p"
        },
        {
            "title": "Judge",
            "type": "p"
        },
        {
            "title": "Justice",
            "type": "p"
        },
        {
            "title": "Brother",
            "type": "p"
        },
        {
            "title": "Sister",
            "type": "p"
        },
        {
            "title": "Prof",
            "type": "p"
        },
        {
            "title": "Prof.",
            "type": "p"
        },
        {
            "title": "Professor",
            "type": "p"
        },
        {
            "title": "Col.",
            "type": "p"
        },
        {
            "title": "Colonel",
            "type": "p"
        },
        {
            "title": "General",
            "type": "p"
        },
        {
            "title": "Gen.",
            "type": "p"
        },
        {
            "title": "Sgt.",
            "type": "p"
        },
        {
            "title": "Sergeant",
            "type": "p"
        },
        {
            "title": "Agent",
            "type": "p"
        },
        {
            "title": "Principal",
            "type": "p"
        },
        {
            "title": "Queen",
            "type": "p"
        },
        {
            "title": "King",
            "type": "p"
        },
        {
            "title": "BA",
            "type": "s"
        },
        {
            "title": "B.A.",
            "type": "s"
        },
        {
            "title": "BS",
            "type": "s"
        },
        {
            "title": "B.S.",
            "type": "s"
        },
        {
            "title": "MBA",
            "type": "s"
        },
        {
            "title": "M.B.A.",
            "type": "s"
        },
        {
            "title": "PhD",
            "type": "s"
        },
        {
            "title": "Ph.D",
            "type": "s"
        },
        {
            "title": "Sr.",
            "type": "s"
        },
        {
            "title": "Sr",
            "type": "s"
        },
        {
            "title": "Senior",
            "type": "s"
        },
        {
            "title": "Jr.",
            "type": "s"
        },
        {
            "title": "Jr",
            "type": "s"
        },
        {
            "title": "Junior",
            "type": "s"
        },
        {
            "title": "I",
            "type": "s"
        },
        {
            "title": "II",
            "type": "s"
        },
        {
            "title": "III",
            "type": "s"
        },
        {
            "title": "IV",
            "type": "s"
        },
        {
            "title": "V",
            "type": "s"
        },
        {
            "title": "VI",
            "type": "s"
        },
        {
            "title": "VII",
            "type": "s"
        },
        {
            "title": "VIII",
            "type": "s"
        },
        {
            "title": "IX",
            "type": "s"
        },
        {
            "title": "X",
            "type": "s"
        }
    ]
}`)

Defaults provides a set of defaults at the package level.

Functions

func LoadTitleData

func LoadTitleData() error

LoadTitleData creates a map consisting of title prefixes and suffixes that are common. This can be called optionally by the consumer if they are expecting their input data to include prefixes and/or suffixes

func LoadTitleDataCSV

func LoadTitleDataCSV(b *bytes.Buffer) error

LoadTitleDataCSV works the same as LoadTitleData(), but expects a file path as input with should contain a .csv file extension.

Types

type Name

type Name struct {
	First, Middle, Last, Prefix, Suffix string
	// contains filtered or unexported fields
}

Name contains a common list fields that could be combined as a person's full name

func New

func New(full string) *Name

New returns a pointer to a Name and initializes full with full

func (*Name) FormatName

func (n *Name) FormatName()

FormatName creates a struct member with a formatted full name.

func (*Name) FormattedName

func (n *Name) FormattedName() string

FormattedName returns the formatted full name string created by FormatFullName()

func (*Name) Initials

func (n *Name) Initials(dots bool) string

Initials returns the acronym for the Name. The argument del will default to an empty string, but a common input would be "." producing a result with periods (eg. J.K.M.)

func (*Name) SeparateName

func (n *Name) SeparateName(sep string)

SeparateName uses receiver n, and parses full according to common logic and parses the full name with the fields separated. If full is empty, then Name will reflect the zero values appropriately. If full cannot be split on sep, then Name.First will be set as the entire value of full.

Jump to

Keyboard shortcuts

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