Skip to content
This repository has been archived by the owner on Dec 7, 2023. It is now read-only.

Commit

Permalink
add - doc - Added finding first and last names
Browse files Browse the repository at this point in the history
We've added finding first and last names

---

You can now find the first and the last names as desired. Please note that searches are case-sensitive.

---

Type: add
Breaking: False
Doc Required: True
Part: 1/1
  • Loading branch information
AptiviCEO committed Oct 18, 2023
1 parent a177df0 commit ea6b3d7
Show file tree
Hide file tree
Showing 2 changed files with 149 additions and 0 deletions.
5 changes: 5 additions & 0 deletions Namer.Demo/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,11 @@ static void Main()
Console.WriteLine("Generate 5 names with custom name and surname prefix\n");
var namescomplete = NameGenerator.GenerateNames(5, "Ev", "n", "Na", "lo", genderType);
Console.WriteLine("- {0}\n", string.Join(", ", namescomplete));

// Find first names
Console.WriteLine("Find first names\n");
var findnames = NameGenerator.FindFirstNames("Mic", "", "", genderType);
Console.WriteLine("- {0}\n", string.Join(", ", findnames));
}
}
}
Expand Down
144 changes: 144 additions & 0 deletions Namer/NameGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,98 @@ public static async Task<string[]> GenerateLastNamesAsync(int Count, string Surn
return GenerateLastNameArray(Count, SurnamePrefix, SurnameSuffix);
}

/// <summary>
/// Generates the first names
/// </summary>
/// <param name="nameSearchTerm">Search term for the name</param>
/// <param name="genderType">Gender type to use when generating names</param>
/// <returns>List of generated names</returns>
public static string[] FindFirstNames(string nameSearchTerm, NameGenderType genderType = NameGenderType.Unified) =>
FindFirstNames(nameSearchTerm, "", "", genderType);

/// <summary>
/// Generates the first names
/// </summary>
/// <param name="nameSearchTerm">Search term for the name</param>
/// <param name="NamePrefix">What should the name start with?</param>
/// <param name="NameSuffix">What should the name end with?</param>
/// <param name="genderType">Gender type to use when generating names</param>
/// <returns>List of generated names</returns>
public static string[] FindFirstNames(string nameSearchTerm, string NamePrefix, string NameSuffix, NameGenderType genderType = NameGenderType.Unified)
{
// Initialize names
PopulateNames(genderType);
return GenerateFirstNameArray(nameSearchTerm, NamePrefix, NameSuffix);
}

/// <summary>
/// [Async] Generates the first names
/// </summary>
/// <param name="nameSearchTerm">Search term for the name</param>
/// <param name="genderType">Gender type to use when generating names</param>
/// <returns>List of generated names</returns>
public static async Task<string[]> FindFirstNamesAsync(string nameSearchTerm, NameGenderType genderType = NameGenderType.Unified) =>
await FindFirstNamesAsync(nameSearchTerm, "", "", genderType);

/// <summary>
/// [Async] Generates the first names
/// </summary>
/// <param name="nameSearchTerm">Search term for the name</param>
/// <param name="NamePrefix">What should the name start with?</param>
/// <param name="NameSuffix">What should the name end with?</param>
/// <param name="genderType">Gender type to use when generating names</param>
/// <returns>List of generated names</returns>
public static async Task<string[]> FindFirstNamesAsync(string nameSearchTerm, string NamePrefix, string NameSuffix, NameGenderType genderType = NameGenderType.Unified)
{
// Initialize names
await PopulateNamesAsync(genderType);
return GenerateFirstNameArray(nameSearchTerm, NamePrefix, NameSuffix);
}

/// <summary>
/// Generates the last names
/// </summary>
/// <param name="nameSearchTerm">Search term for the name</param>
/// <returns>List of generated names</returns>
public static string[] FindLastNames(string nameSearchTerm) =>
FindLastNames(nameSearchTerm, "", "");

/// <summary>
/// Generates the last names
/// </summary>
/// <param name="nameSearchTerm">Search term for the name</param>
/// <param name="SurnamePrefix">What should the surname start with?</param>
/// <param name="SurnameSuffix">What should the surname end with?</param>
/// <returns>List of generated names</returns>
public static string[] FindLastNames(string nameSearchTerm, string SurnamePrefix, string SurnameSuffix)
{
// Initialize names
PopulateNames();
return GenerateLastNameArray(nameSearchTerm, SurnamePrefix, SurnameSuffix);
}

/// <summary>
/// [Async] Generates the last names
/// </summary>
/// <param name="nameSearchTerm">Search term for the name</param>
/// <returns>List of generated names</returns>
public static async Task<string[]> FindLastNamesAsync(string nameSearchTerm) =>
await FindLastNamesAsync(nameSearchTerm, "", "");

/// <summary>
/// [Async] Generates the last names
/// </summary>
/// <param name="nameSearchTerm">Search term for the name</param>
/// <param name="SurnamePrefix">What should the surname start with?</param>
/// <param name="SurnameSuffix">What should the surname end with?</param>
/// <returns>List of generated names</returns>
public static async Task<string[]> FindLastNamesAsync(string nameSearchTerm, string SurnamePrefix, string SurnameSuffix)
{
// Initialize names
await PopulateNamesAsync();
return GenerateLastNameArray(nameSearchTerm, SurnamePrefix, SurnameSuffix);
}

internal static string[] GenerateFirstNameArray(int Count, string NamePrefix, string NameSuffix)
{
var random = new Random();
Expand Down Expand Up @@ -335,6 +427,58 @@ internal static string[] GenerateLastNameArray(int Count, string SurnamePrefix,
return surnamesList.ToArray();
}

internal static string[] GenerateFirstNameArray(string nameSearchTerm, string NamePrefix, string NameSuffix)
{
var random = new Random();
List<string> namesList = new();

// Check if the prefix and suffix check is required
bool NamePrefixCheckRequired = !string.IsNullOrEmpty(NamePrefix);
bool NameSuffixCheckRequired = !string.IsNullOrEmpty(NameSuffix);

// Process the names according to suffix and/or prefix check requirement
string[] ProcessedNames = Names;
if (NamePrefixCheckRequired && NameSuffixCheckRequired)
ProcessedNames = Names.Where((str) => str.StartsWith(NamePrefix) && str.EndsWith(NameSuffix)).ToArray();
else if (NamePrefixCheckRequired)
ProcessedNames = Names.Where((str) => str.StartsWith(NamePrefix)).ToArray();
else if (NameSuffixCheckRequired)
ProcessedNames = Names.Where((str) => str.EndsWith(NameSuffix)).ToArray();
ProcessedNames = ProcessedNames.Where(str => str.Contains(nameSearchTerm)).ToArray();

// Check the names
if (ProcessedNames.Length == 0)
throw new Exception("The names are not found! Please ensure that the name conditions are correct.");

return ProcessedNames;
}

internal static string[] GenerateLastNameArray(string nameSearchTerm, string SurnamePrefix, string SurnameSuffix)
{
var random = new Random();
List<string> surnamesList = new();

// Check if the prefix and suffix check is required
bool SurnamePrefixCheckRequired = !string.IsNullOrEmpty(SurnamePrefix);
bool SurnameSuffixCheckRequired = !string.IsNullOrEmpty(SurnameSuffix);

// Process the surnames according to suffix and/or prefix check requirement
string[] ProcessedSurnames = Surnames;
if (SurnamePrefixCheckRequired && SurnameSuffixCheckRequired)
ProcessedSurnames = Surnames.Where((str) => str.StartsWith(SurnamePrefix) && str.EndsWith(SurnameSuffix)).ToArray();
else if (SurnamePrefixCheckRequired)
ProcessedSurnames = Surnames.Where((str) => str.StartsWith(SurnamePrefix)).ToArray();
else if (SurnameSuffixCheckRequired)
ProcessedSurnames = Surnames.Where((str) => str.EndsWith(SurnameSuffix)).ToArray();
ProcessedSurnames = ProcessedSurnames.Where(str => str.Contains(nameSearchTerm)).ToArray();

// Check the surnames
if (ProcessedSurnames.Length == 0)
throw new Exception("The surnames are not found! Please ensure that the surname conditions are correct.");

return ProcessedSurnames;
}

internal static string[] GenerateNameArray(int Count, string NamePrefix, string NameSuffix, string SurnamePrefix, string SurnameSuffix)
{
List<string> namesList = new();
Expand Down

0 comments on commit ea6b3d7

Please sign in to comment.