Skip to content

Commit

Permalink
Fix: RUTimeUnitWithinFormatParser to lazy loading
Browse files Browse the repository at this point in the history
  • Loading branch information
Wanasit Tanakitrungruang committed Nov 19, 2023
1 parent 96dcd11 commit cb0bdd4
Showing 1 changed file with 3 additions and 10 deletions.
13 changes: 3 additions & 10 deletions src/locales/ru/parsers/RUTimeUnitWithinFormatParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,14 @@ import { AbstractParserWithWordBoundaryChecking } from "../../../common/parsers/
const PATTERN = `(?:(?:около|примерно)\\s*(?:~\\s*)?)?(${TIME_UNITS_PATTERN})${REGEX_PARTS.rightBoundary}`;

export default class RUTimeUnitWithinFormatParser extends AbstractParserWithWordBoundaryChecking {
private readonly patternWithPrefix: RegExp;
private readonly patternWithoutPrefix: RegExp;

constructor() {
super();
this.patternWithPrefix = new RegExp(`(?:в течение|в течении)\\s*${PATTERN}`, REGEX_PARTS.flags);
this.patternWithoutPrefix = new RegExp(PATTERN, REGEX_PARTS.flags);
}

patternLeftBoundary(): string {
return REGEX_PARTS.leftBoundary;
}

innerPattern(context: ParsingContext): RegExp {
return context.option.forwardDate ? this.patternWithoutPrefix : this.patternWithPrefix;
return context.option.forwardDate
? new RegExp(PATTERN, REGEX_PARTS.flags)
: new RegExp(`(?:в течение|в течении)\\s*${PATTERN}`, REGEX_PARTS.flags);
}

innerExtract(context: ParsingContext, match: RegExpMatchArray): ParsingComponents {
Expand Down

0 comments on commit cb0bdd4

Please sign in to comment.