Documentation ¶
Index ¶
- type Generator
- func (gen *Generator) Adjective(mods ...Mod) (string, error)
- func (gen *Generator) Noun(mods ...Mod) (string, error)
- func (gen *Generator) Phrase(pattern string) (string, error)
- func (gen *Generator) Transform(word string, mods ...Mod) (string, error)
- func (gen *Generator) Verb(mods ...Mod) (string, error)
- type Mod
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Generator ¶
type Generator struct {
// contains filtered or unexported fields
}
Generates random phrases or words.
func DefaultGenerator ¶ added in v0.5.0
Returns a new Generator with default word lists.
func NewGenerator ¶
Initializes a new Generator with provided lists. Returns error if any of the lists is empty.
func (*Generator) Adjective ¶
Generates a single random adjective and transforms it according to mods. Returns an error if an undefined Mod is received.
func (*Generator) Noun ¶
Generates a single random noun and transforms it according to mods. Returns an error if an undefined Mod is received.
func (*Generator) Phrase ¶
Generates a phrase given the pattern.
Syntax:
Insertion: %% - inserts '%' sign %a - inserts a random adjective %n - inserts a random noun %v - inserts a random verb Transformation: %2 - transforms a verb into its Past Simple form (2nd form) %3 - transforms a verb into its Past Participle form (3rd form) %N - transforms a verb into its Present Simple form (now) %g - transforms a verb into gerund %p - transform a noun or a verb (Present Simple) into its plural form %l - transform a word to lower case %t - transform a word to Title Case %u - transform a word to UPPER CASE
Error is returned if:
- provided pattern is empty
- character other than the above is escaped with a '%' sign
- a single '%' ends the pattern
Error is not returned if:
- incompatible modifier is assigned to the word
- duplicate modifier is assigned to the same word
Example phrase:
"%tn %2v a %ua %un" may produce "Serenade perplexed a STRAY SUPERBUG"
type Mod ¶ added in v0.2.0
type Mod uint8
Modification parameter for a generated word
const ( // Transform a noun or a verb (Present Simple) into its plural form MOD_PLURAL Mod = iota // Add Past Simple suffix to a verb or substitute its irregular form MOD_PAST_SIMPLE // Add Past Simple suffix to a regular verb or substitute Past Participle form to an irregular one MOD_PAST_PARTICIPLE // Add Present Simple suffix to a verb (-s, -es) MOD_PRESENT_SIMPLE // Create gerund form of a verb (-ing) MOD_GERUND // Transform a word to lower case MOD_CASE_LOWER // Transform a word to Title Case MOD_CASE_TITLE // Transform a word to UPPER CASE MOD_CASE_UPPER )
Click to show internal directories.
Click to hide internal directories.