Skip to content

Commit

Permalink
wrap up name impl
Browse files Browse the repository at this point in the history
  • Loading branch information
BolajiOlajide committed Sep 4, 2024
1 parent 2f2955d commit 9f73747
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 6 deletions.
46 changes: 40 additions & 6 deletions lib/name.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,44 @@
import type { Localizer } from './locales';
import { BeninLocale } from './locales/benin';
import { EfikLocale } from './locales/efik';
import { EnglishLocale } from './locales/english';
import { HausaLocale } from './locales/hausa';
import { IgboLocale } from './locales/igbo';
import { UrhoboLocale } from './locales/urhobo';
import { YorubaLocale } from './locales/yoruba';
import type { Random } from './random';
import { Gender, type Locale } from './types';
import { Gender, Locale } from './types';

export class Name {
private locale: Locale;
private random: Random;
private localizer: Localizer;

constructor(locale: Locale, random: Random) {
this.locale = locale;
this.random = random;
this.localizer = this.setLocalizer();
}

private setLocalizer(): Localizer {
switch (this.locale) {
case Locale.BENIN:
return new BeninLocale(this.random);
case Locale.YORUBA:
return new YorubaLocale(this.random);
case Locale.IGBO:
return new IgboLocale(this.random);
case Locale.HAUSA:
return new HausaLocale(this.random);
case Locale.EFIK:
return new EfikLocale(this.random);
case Locale.URHOBO:
return new UrhoboLocale(this.random);
case Locale.ENGLISH:
return new EnglishLocale(this.random);
default:
throw new Error(`Locale "${this.locale}" not supported`);
}
}

private selectRandomGender(): Gender {
Expand All @@ -16,11 +47,14 @@ export class Name {

firstName(gender?: Gender): string {
const chosenGender = gender ?? this.selectRandomGender();
return '';
return this.localizer.firstName(chosenGender);
}

lastName(): string {
return this.localizer.lastName();
}

// if (gender === 0) {
// return ngFaker.random.arrayElement(ngFaker.definitions.name.male_first_name);
// }
// return ngFaker.random.arrayElement(ngFaker.definitions.name.female_first_name);
prefix(): string {
return this.localizer.prefix();
}
}
1 change: 1 addition & 0 deletions lib/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ export enum Locale {
HAUSA,
EFIK,
BENIN,
URHOBO,
}

export enum Gender {
Expand Down

0 comments on commit 9f73747

Please sign in to comment.