github.com/LanderTome/numerologyCalculator@v1.0.2/numerology/numberSystems.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  	"encoding/json"
    16  	"strings"
    17  )
    18  
    19  // NumberSystem contains the information necessary to convert letters to their numerological value.
    20  type NumberSystem struct {
    21  	// Name of the NumberSystem that is used to translate to and from JSON.
    22  	Name string
    23  
    24  	// NumberMapping is a map of letters and their corresponding value.
    25  	NumberMapping map[int32]int
    26  
    27  	// ValidNumbers shows all the numbers that the number system accepts. The Chaldean number system,
    28  	// in particular, does not use the number 9 in conversions.
    29  	ValidNumbers []int
    30  }
    31  
    32  // MarshalJSON returns the name of the number system because it doesn't make sense to encode the whole struct
    33  // for output to JSON.
    34  func (ns NumberSystem) MarshalJSON() ([]byte, error) {
    35  	return json.Marshal(strings.ToLower(ns.Name))
    36  }
    37  
    38  // UnmarshalJSON translates the name of the number system to the appropriate NumberSystem struct.
    39  func (ns *NumberSystem) UnmarshalJSON(value []byte) error {
    40  	numberSystem, err := GetNumberSystem(strings.Trim(string(value), `"`))
    41  	*ns = numberSystem
    42  	return err
    43  }
    44  
    45  // Todo: Add non-English characters like é, ö, å, etc.
    46  
    47  // The conversion table for the Chaldean number system.
    48  var Chaldean = NumberSystem{
    49  	Name: "Chaldean",
    50  	NumberMapping: map[int32]int{
    51  		'a': 1, 'i': 1, 'j': 1, 'q': 1, 'y': 1,
    52  		'b': 2, 'k': 2, 'r': 2,
    53  		'c': 3, 'g': 3, 'l': 3, 's': 3,
    54  		'd': 4, 'm': 4, 't': 4,
    55  		'e': 5, 'h': 5, 'n': 5, 'x': 5,
    56  		'u': 6, 'v': 6, 'w': 6,
    57  		'o': 7, 'z': 7,
    58  		'f': 8, 'p': 8,
    59  		'0': 0, '1': 1, '2': 2, '3': 3, '4': 4,
    60  		'5': 5, '6': 6, '7': 7, '8': 8, '9': 9,
    61  		' ': 0, '.': 0, '-': 0, // Common acceptable characters in names that have no value.
    62  	},
    63  	ValidNumbers: []int{1, 2, 3, 4, 5, 6, 7, 8},
    64  }
    65  
    66  // The conversion table for the Pythagorean number system.
    67  var Pythagorean = NumberSystem{
    68  	Name: "Pythagorean",
    69  	NumberMapping: map[int32]int{
    70  		'a': 1, 'j': 1, 's': 1,
    71  		'b': 2, 'k': 2, 't': 2,
    72  		'c': 3, 'l': 3, 'u': 3,
    73  		'd': 4, 'm': 4, 'v': 4,
    74  		'e': 5, 'n': 5, 'w': 5,
    75  		'f': 6, 'o': 6, 'x': 6,
    76  		'g': 7, 'p': 7, 'y': 7,
    77  		'h': 8, 'q': 8, 'z': 8,
    78  		'i': 9, 'r': 9,
    79  		'0': 0, '1': 1, '2': 2,
    80  		'3': 3, '4': 4, '5': 5,
    81  		'6': 6, '7': 7, '8': 8,
    82  		'9': 9,
    83  		' ': 0, '.': 0, '-': 0, // Commonly acceptable characters in names that have no value.
    84  	},
    85  	ValidNumbers: []int{1, 2, 3, 4, 5, 6, 7, 8, 9},
    86  }