Skip to content

Commit

Permalink
Refactor: Extracted regex creation logic to a new class
Browse files Browse the repository at this point in the history
  • Loading branch information
revolter committed Feb 24, 2024
1 parent 0a50187 commit a127ce2
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/recipes/hanayama_huzzles/HanayamaHuzzlesRecipe.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { MarkdownTableConverter } from 'src/markdown/MarkdownTableConverter';
import { MarkdownTableFactory } from 'src/markdown/MarkdownTableFactory';
import { RegexFactory } from 'src/regex/RegexFactory';
import { WebsiteScraper } from 'src/scraping/WebsiteScraper';
import { TrackablesUpdater } from 'src/tracking/TrackablesUpdater';
import { Recipe } from '../Recipe';
Expand Down Expand Up @@ -98,7 +99,7 @@ export class HanayamaHuzzlesRecipe implements Recipe {

#markdownTableStringToHuzzles(markdownTableString: string): HanayamaHuzzle[] {
const arrayOfArrays = this.markdownTableConverter.arrayOfArraysFromString(markdownTableString);
const imageLinkRegex = new RegExp(/!\[[^\]]+\]\((?<link>[^)]+)(?=\))/g); // https://regex101.com/r/YlCOgc/2
const imageLinkRegex = new RegexFactory().imageMarkdownLinkRegex();

return arrayOfArrays.flatMap(array => {
if (array.length < 5) {
Expand Down
5 changes: 5 additions & 0 deletions src/regex/RegexFactory.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export class RegexFactory {
imageMarkdownLinkRegex(): RegExp {
return new RegExp(/!\[[^\]]+\]\((?<link>[^)]+)(?=\))/g); // https://regex101.com/r/YlCOgc/2
}
}

0 comments on commit a127ce2

Please sign in to comment.