# Module: constantStringParsing

Contains all system defined business rules for parsing strings related to constants.

Author:
  - Seth Hollingsead
Copyright:
  - Copyright © 2022-… by Seth Hollingsead. All rights reserved
Source:
  - businessRules/rules/stringParsing/constantStringParsing.js, line 1

### Requires

- module:ruleParsing
- module:configurator
- module:loggers
- module:data
- @haystacks/constants
- chalk
- n-readlines
- path

### Methods

#### (inner) constantsFulfillmentSystem(inputData, inputMetaData) → {string}

Determines what is the most optimized way to define a new constant using existing constant strings.

##### Parameters:

Name | Type | Description
--- | --- | ---
`inputData` | string | The constant to be defined/fulfilled.
`inputMetaData` | string | The original user-defined constant to be fulfilled, so the recursive algorithm can continue processing the rest of the string, after a first match is found.

Author:
  - Seth Hollingsead
Source:
  - businessRules/rules/stringParsing/constantStringParsing.js, line 566

##### Returns:

The fully optimized definition for the new constant.

Type
  string

#### (inner) constantsOptimizedFulfillmentSystem(inputData, inputMetaData) → {string}

Determines what is the most optimized way to define a string using existing constant strings.

##### Parameters:

Name | Type | Description
--- | --- | ---
`inputData` | string | the string that should be determined or find a constant to fulfill part of the string.
`inputMetaData` | string | Not used for this business rule.

Author:
  - Seth Hollingsead
Source:
  - businessRules/rules/stringParsing/constantStringParsing.js, line 534

##### Returns:

A constant that represents part of the input string.

Type
  string

#### (inner) convertConstantTypeToConstantPrefix(inputData, inputMetaData) → {string}

Converts the constant type to a constant prefix so it can be used to assist with defining an optimized constant definition.

##### Parameters:

Name | Type | Description
--- | --- | ---
`inputData` | string | The constant type that should be used when converting to a constant prefix.
`inputMetaData` | string | Not used for this business rule.

Author:
  - Seth Hollingsead
Source:
  - businessRules/rules/stringParsing/constantStringParsing.js, line 505

##### Returns:

The appropriate constant prefix.

Type
  string

#### (inner) determineConstantsContextQualifiedPrefix(inputData, inputMetaData) → {string}

Takes the filename to a constants file and determines The standard prefix that should be used in the code to reference that constants file.

##### Parameters:

Name | Type | Description
--- | --- | ---
`inputData` | string | The filename of the constants file or the full path and file name of the constants file. (Should work just the same with either one)
`inputMetaData` | string | Not used for this business rule.

Author:
  - Seth Hollingsead
Source:
  - businessRules/rules/stringParsing/constantStringParsing.js, line 115

##### Returns:

A string code that represents the method to reference a constants file in the code.

Type
  string

#### (inner) determineSuggestedConstantsValidationLineOfCode(inputData, inputMetaData) → {string}

Takes the name of the missing constant and determines a suggested lin of code to ad to the appropriate constants validation file. This will make it really easy for developers to maintain the constants validation system.

##### Parameters:

Name | Type | Description
--- | --- | ---
`inputData` | string | The name of the constant file that is missing and should have a line of code generated for it.
`inputMetaData` | string | The prefix used to reference the constants file in the code.

Author:
  - Seth Hollingsead
Source:
  - businessRules/rules/stringParsing/constantStringParsing.js, line 147

##### Returns:

The suggested line of code that should be added to the appropriate constants validation code file.

Type
  string

#### (inner) doesConstantExist(inputData, inputMetaData) → {boolean}

Walks through all of the constants validation files and checks to see if any of the expected values match the string that is passed in.

##### Parameters:

Name | Type | Description
--- | --- | ---
`inputData` | string | The value that should be looked for in all the constants files.
`inputMetaData` | string | Not used for this business rule.

Author:
  - Seth Hollingsead
Source:
  - businessRules/rules/stringParsing/constantStringParsing.js, line 222

##### Returns:

True or False to indicate if a matching constant definition was found or not.

Type
  boolean

#### (inner) findConstantName(inputData, inputMetaData) → {string}

Looks through a string and tries to weed out a constant name.

##### Parameters:

Name | Type | Description
--- | --- | ---
`inputData` | string | The string that should be searched for a constant name.
`inputMetaData` | string | Not used for this business rule.

Author:
  - Seth Hollingsead
Source:
  - businessRules/rules/stringParsing/constantStringParsing.js, line 450

##### Returns:

The name of the constant that was found.

Type
  string

#### (inner) getConstantActualValue(inputData, inputMetaData) → {string}

Determines the actual value of the named constant given the constant type.

##### Parameters:

Name | Type | Description
--- | --- | ---
`inputData` | string | The name of the constant we are looking for to get the actual value of the constant.
`inputMetaData` | string | (OPTIONAL) The type or library where the constant should be found.

Author:
  - Seth Hollingsead
Source:
  - businessRules/rules/stringParsing/constantStringParsing.js, line 333

##### Returns:

The actual value of the string.

Type
  string

#### (inner) getConstantName(inputData, inputMetaData) → {string}

Gets the constant name given the constant value, or what the constant should resolve as. Can only return the first instance.

##### Parameters:

Name | Type | Description
--- | --- | ---
`inputData` | string | The constant string value that should be used when getting the constant name.
`inputMetaData` | string | Not used for this business rule.

Author:
  - Seth Hollingsead
Source:
  - businessRules/rules/stringParsing/constantStringParsing.js, line 400

##### Returns:

The name of the constant: eg: cSystem

Type
  string

#### (inner) getConstantType(inputData, inputMetaData) → {string}

Determines what constant library a particular constant is defined in. (This will aid developers who are trying to understand & develop under this complicated constants system.)

##### Parameters:

Name | Type | Description
--- | --- | ---
`inputData` | string | The string value that should be searched in all of the constants libraries.
`inputMetaData` | boolean | True or False to indicate if the function should exit on first discovery or continue to discover all possible matches.

Author:
  - Seth Hollingsead
Source:
  - businessRules/rules/stringParsing/constantStringParsing.js, line 272

##### Returns:

A list of constants libraries where the constant was found to be defined in.

Type
  string

#### (inner) isConstantTypeValid(inputData, inputMetaData) → {boolean}

Determines if a string is a valid constant type/library or not.

##### Parameters:

Name | Type | Description
--- | --- | ---
`inputData` | string | The string that should be validated if it is a valid constant type or not.
`inputMetaData` | string | Not used for this business rule.

Author:
  - Seth Hollingsead
Source:
  - businessRules/rules/stringParsing/constantStringParsing.js, line 475

##### Returns:

True or False to indicate if the string is a valid constant type/library that exists within the system or not.

Type
  boolean

#### (inner) isConstantValid(inputData, inputMetaData) → {boolean}

Determines if the user entered some valid input constant string or not. User must have entered more than 4 characters.

##### Parameters:

Name | Type | Description
--- | --- | ---
`inputData` | string | The value of the constant as a string.
`inputMetaData` | string | Not used for this business rule.

Author:
  - Seth Hollingsead
Source:
  - businessRules/rules/stringParsing/constantStringParsing.js, line 678

##### Returns:

True or False to indicate if the user entered a valid constant or not.

Type
  boolean

#### (inner) validateConstantsDataValidation(inputData, inputMetaData) → {boolean}

Validates that validation data to ensure that all the contents of the constants validation data matches with the actual constants definitions.

##### Parameters:

Name | Type | Description
--- | --- | ---
`inputData` | string | the path of the constants file that should be validated.
`inputMetaData` | string | The name of the data hive that contains the appropriate matching constants validation data.

Author:
  - Seth Hollingsead
Source:
  - businessRules/rules/stringParsing/constantStringParsing.js, line 34

##### Returns:

True or False to indicate if all of the contents of the constants are fully validated or not.

Type
  boolean

#### (inner) validateConstantsDataValidationLineItemName(inputData, inputMetaData) → {boolean}

Loops through all of the constants validation data and verifies if a matching constant definition can be found, or not found.

##### Parameters:

Name | Type | Description
--- | --- | ---
`inputData` | string | the constant definition that should be searched for.
`inputMetaData` | string | The name of the data hive that contains the appropriate matching constants validation data.

Author:
  - Seth Hollingsead
Source:
  - businessRules/rules/stringParsing/constantStringParsing.js, line 191

##### Returns:

True or False to indicate if a match was found or not found.

Type
  boolean

#### (inner) validateConstantsDataValues(inputData, inputMetaData) → {boolean}

Iterates over all the constants values in the constants validation data specified by the input parameter and validates the content.

##### Parameters:

Name | Type | Description
--- | --- | ---
`inputData` | string | The name of the data-hive that should contain all of the validation data that should be used to execute the validation procedures.
`inputMetaData` | string | Not used for this business rule.

Author:
  - Seth Hollingsead
Source:
  - businessRules/rules/stringParsing/constantStringParsing.js, line 610

##### Returns:

True or False to indicate if the validation passed for the entire data hive or if it did not pass.

Type
  boolean