Documentation ¶
Overview ¶
Package mnemonic a terrible mnemonic generator
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type StaticWordGenerator ¶
type StaticWordGenerator struct {
// contains filtered or unexported fields
}
StaticWordGenerator is a word generator that returns a static word
func NewStaticWordGenerator ¶
func NewStaticWordGenerator(word string, funcName string) *StaticWordGenerator
NewStaticWordGenerator returns a word generator that returns a static word
Could be used like
mnemonic.NewWnramWordGenerator("soft", wnram.Adjective.String())
func (*StaticWordGenerator) Generate ¶
func (w *StaticWordGenerator) Generate(letter string) string
Generate returns a single word
Example ¶
generator := NewStaticWordGenerator("dancing", "adj") fmt.Println(generator.Generate("d"))
Output: dancing
func (*StaticWordGenerator) GetFuncName ¶
func (w *StaticWordGenerator) GetFuncName() string
GetFuncName gets the function name
Example ¶
generator := NewStaticWordGenerator("dancing", "adj") fmt.Println(generator.GetFuncName())
Output: adj
type Template ¶
type Template interface { GetTemplate() string GetParameters() map[string]string GetUsedFunctions() []string }
Template to be used to generate the mnemonic
type TemplateBase ¶
type TemplateBase struct {
// contains filtered or unexported fields
}
TemplateBase is a template to generate a mnemonic
func NewTemplate ¶
func NewTemplate(letters []string) *TemplateBase
NewTemplate returns a template to generate a mnemonic
Might be used like this:
template := mnemonic.NewTemplate([]string{"e", "x", "a", "m", "p", "l", "e"})
Example ¶
NewTemplate([]string{"a"})
Output:
func (TemplateBase) GetParameters ¶
func (t TemplateBase) GetParameters() map[string]string
GetParameters returns a map with the parameters for this template in
Example ¶
actual := NewTemplate([]string{"a"}) for key, value := range actual.GetParameters() { fmt.Println("Key:", key, "Value:", value) }
Output: Key: Param1 Value: a
func (TemplateBase) GetTemplate ¶
func (t TemplateBase) GetTemplate() string
GetTemplate returns a template string compatible with the go template engine
Example ¶
actual := NewTemplate([]string{"a"}) fmt.Println(actual.GetTemplate())
Output: {{ .Param1 | noun }}.
func (TemplateBase) GetUsedFunctions ¶
func (t TemplateBase) GetUsedFunctions() []string
GetUsedFunctions returns the used functions
Example ¶
actual := NewTemplate([]string{"a"}) fmt.Println(actual.GetUsedFunctions()[0])
Output: noun
type TemplateParser ¶
type TemplateParser interface {
Parse(userTemplate string, input []string, writer *bufio.Writer) error
}
TemplateParser interface returned by the NewTemplateParses
type TemplateParserBase ¶
type TemplateParserBase struct {
// contains filtered or unexported fields
}
TemplateParserBase is a parser that can convert a template into a string
func NewTemplateParser ¶
func NewTemplateParser( generator ...WordGenerator, ) *TemplateParserBase
NewTemplateParser returns a new parser that can convert a template into a string
Might be used like this
generator := mnemonic.NewTemplateParser( mnemonic.NewWnramWordGenerator(wn, wnram.Adjective), mnemonic.NewWnramWordGenerator(wn, wnram.Noun), mnemonic.NewWnramWordGenerator(wn, wnram.Verb), mnemonic.NewWnramWordGenerator(wn, wnram.Adverb), )
Example ¶
NewTemplateParser( NewStaticWordGenerator("dancing", "adj"), NewStaticWordGenerator("eggs", "noun"), NewStaticWordGenerator("move", "verb"), NewStaticWordGenerator("outward", "adv"), )
Output:
func (*TemplateParserBase) Parse ¶
func (g *TemplateParserBase) Parse(userTemplate Template, input []string, writer *bufio.Writer) error
Parse returns the parted template
Might be used like this
err = generator.Parse(template, letters, bufio.NewWriter(os.Stdout))
Or you can capture the string
buffer := &bytes.Buffer{} writer := bufio.NewWriter(buffer) _ = generator.Parse(template, letters, writer) fmt.Println(buffer.String())
Example ¶
letters := strings.Split("demo", "") template := NewTemplate(letters) generator := NewTemplateParser( NewStaticWordGenerator("dancing", "adj"), NewStaticWordGenerator("eggs", "noun"), NewStaticWordGenerator("move", "verb"), NewStaticWordGenerator("outward", "adv"), ) buffer := &bytes.Buffer{} writer := bufio.NewWriter(buffer) err := generator.Parse(template, letters, writer) if err != nil { log.Fatal(err) return } fmt.Println(buffer.String())
Output: dancing eggs move outward.
type WnramWordGenerator ¶
type WnramWordGenerator struct {
// contains filtered or unexported fields
}
WnramWordGenerator is a word generator that pulls random words from a WordNet dictionary
func NewWnramWordGenerator ¶
func NewWnramWordGenerator(wn *wnram.Handle, partOfSpeech wnram.PartOfSpeech) *WnramWordGenerator
NewWnramWordGenerator returns a word generator that pulls random words from a WordNet dictionary
See the library http://github.com/lloyd/wnram
Get dictionary files from http://wordnet.princeton.edu/
Could be used like
wn, _ := wnram.New(dictDir) mnemonic.NewWnramWordGenerator(wn, wnram.Adjective)
func (*WnramWordGenerator) Generate ¶
func (w *WnramWordGenerator) Generate(letter string) string
Generate returns a random word beginning with a given letter
func (*WnramWordGenerator) GetFuncName ¶
func (w *WnramWordGenerator) GetFuncName() string
GetFuncName the function name
type WordGenerator ¶
WordGenerator Generates random words beginning with a single letter