github.com/LanderTome/numerologyCalculator@v1.0.2/numerology/calculateNames.go (about) 1 // Copyright 2021 Robert D. Wukmir 2 // This file is subject to the terms and conditions defined in 3 // the LICENSE file, which is part of this source code package. 4 // 5 // Unless required by applicable law or agreed to in writing, 6 // software distributed under the License is distributed on an 7 // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, 8 // either express or implied. See the License for the specific 9 // language governing permissions and limitations under the 10 // License. 11 12 package numerology 13 14 import ( 15 "errors" 16 "strings" 17 ) 18 19 // NameNumerology is used as a struct to store the name and configuration information that is required 20 // to calculate the numerological values of names. 21 type NameNumerology struct { 22 Name string 23 *NameOpts 24 *NameSearchOpts 25 mask *maskStruct 26 counts *map[int32]int 27 unknowns *unknownCharacters 28 } 29 30 // initMask builds the maskStruct as it is needed. 31 func (n *NameNumerology) initMask() { 32 if n.mask == nil { 33 m := maskConstructor(n.Name) 34 n.mask = &m 35 } 36 } 37 38 // Full contains the numerological calculations done using all the letters of the given name. Sometimes referred to as 39 // the Destiny or Expression number. 40 func (n NameNumerology) Full() (result NumerologicalResult) { 41 n.initMask() 42 return calculateCoreNumber(n.Name, n.MasterNumbers, n.ReduceWords, n.NumberSystem, n.mask.Full()) 43 } 44 45 // Destiny is an alias for Full(). 46 func (n NameNumerology) Destiny() (destiny NumerologicalResult) { 47 return n.Full() 48 } 49 50 // Expression is an alias for Full(). 51 func (n NameNumerology) Expression() (expression NumerologicalResult) { 52 return n.Full() 53 } 54 55 // Vowels contains the numerological calculations done using just the vowel letters of the given name. Sometimes 56 // referred to as Heart's Desire or Soul's Urge number. 57 func (n NameNumerology) Vowels() (result NumerologicalResult) { 58 n.initMask() 59 return calculateCoreNumber(n.Name, n.MasterNumbers, n.ReduceWords, n.NumberSystem, n.mask.Vowels()) 60 } 61 62 // SoulsUrge is an alias for Vowels(). 63 func (n NameNumerology) SoulsUrge() (soulsUrge NumerologicalResult) { 64 return n.Vowels() 65 } 66 67 // HeartsDesire is an alias for Vowels(). 68 func (n NameNumerology) HeartsDesire() (heartsDesire NumerologicalResult) { 69 return n.Vowels() 70 } 71 72 // Consonants contains the numerological calculations done using just the consonant letters of the given name. 73 // Sometimes referred to as Personality number. 74 func (n NameNumerology) Consonants() (result NumerologicalResult) { 75 n.initMask() 76 return calculateCoreNumber(n.Name, n.MasterNumbers, n.ReduceWords, n.NumberSystem, n.mask.Consonants()) 77 } 78 79 // Personality is an alias for Consonants(). 80 func (n NameNumerology) Personality() (personality NumerologicalResult) { 81 return n.Consonants() 82 } 83 84 // HiddenPassions contains the calculation of the numerological number(s) that repeat the most in the given name. 85 func (n NameNumerology) HiddenPassions() (result HiddenPassionResults) { 86 return hiddenPassions(n.Counts()) 87 } 88 89 // KarmicLessons contains the calculation of the numerological number(s) that do not appear in the given name. 90 func (n NameNumerology) KarmicLessons() (result KarmicLessonResults) { 91 return karmicLessons(n.Counts()) 92 } 93 94 // Search searches the name database for names that satisfy given numerological criteria. 95 func (n NameNumerology) Search(opts NameSearchOpts) (results []NameNumerology, offset int64, err error) { 96 switch strings.Count(n.Name, "?") { 97 case 0: 98 return []NameNumerology{}, 0, errors.New("missing '?' in name") 99 case 1: 100 return nameSearch(n.Name, n.NumberSystem, n.MasterNumbers, n.ReduceWords, opts) 101 default: 102 return []NameNumerology{}, 0, errors.New("too many '?' (only able to search for one '?' at a time)") 103 } 104 } 105 106 // Counts returns a map of each numerological value and how many times it appears in the name. 107 func (n *NameNumerology) Counts() (counts map[int32]int) { 108 if n.counts == nil { 109 counts, _, unknowns := countNumerologicalNumbers(n.Name, n.NumberSystem) 110 n.counts = &counts 111 n.unknowns = &unknowns 112 } 113 return *n.counts 114 } 115 116 // UnknownCharacters is a set of characters that cannot be converted to numerological values. They are 117 // ignored in calculations. 118 func (n *NameNumerology) UnknownCharacters() (unknowns []string) { 119 if n.unknowns == nil { 120 counts, _, unknowns := countNumerologicalNumbers(n.Name, n.NumberSystem) 121 n.counts = &counts 122 n.unknowns = &unknowns 123 } 124 return n.unknowns.Unacceptable().ToStringSlice() 125 } 126 127 // Name calculates various numerological numbers from a given name. Argument numberSystem indicates what 128 // calculation method is used (Pythagorean or Chaldean). Argument reduceWords determines whether each part of 129 // a name is reduced independently before being merged in a final number. 130 func Name(name string, numberSystem NumberSystem, masterNumbers []int, reduceWords bool) (result NameNumerology) { 131 asciiName := ToAscii(name) 132 result = NameNumerology{ 133 Name: asciiName, 134 NameOpts: &NameOpts{ 135 NumberSystem: numberSystem, 136 MasterNumbers: masterNumbers, 137 ReduceWords: reduceWords, 138 }, 139 } 140 return 141 } 142 143 // Names calculates various numerological numbers from a list of given names. Argument numberSystem indicates what 144 // calculation method is used (Pythagorean or Chaldean). Argument reduceWords determines whether each part of 145 // a name is reduced independently before being merged in a final number. 146 func Names(names []string, numberSystem NumberSystem, masterNumbers []int, reduceWords bool) (results []NameNumerology) { 147 opts := NameOpts{ 148 NumberSystem: numberSystem, 149 MasterNumbers: masterNumbers, 150 ReduceWords: reduceWords, 151 } 152 153 for _, n := range names { 154 name := ToAscii(n) 155 results = append(results, NameNumerology{name, &opts, nil, nil, nil, nil}) 156 } 157 return 158 }