chore: Move vocabDef parsing from Note to Term
This commit is contained in:
parent
ee2525797e
commit
6fc6307f6e
|
@ -67,7 +67,7 @@ class Note
|
|||
$note->mediaInfo = $note->parseMediaInfo($note->fields['Notes']);
|
||||
|
||||
// Set VocabKanji field
|
||||
$terms = self::parseVocabDef($note->fields['VocabDef']);
|
||||
$terms = Term::fromVocabDef($note->fields['VocabDef']);
|
||||
if (null !== $terms) {
|
||||
$note->terms = $terms;
|
||||
} else {
|
||||
|
@ -97,7 +97,7 @@ class Note
|
|||
. $separator
|
||||
. $note->fields['VocabDef'];
|
||||
|
||||
$terms = self::parseVocabDef($note->fields['VocabDef']);
|
||||
$terms = Term::fromVocabDef($note->fields['VocabDef']);
|
||||
$note->terms = $terms ?? dd($note->fields['VocabDef']);
|
||||
}
|
||||
|
||||
|
@ -161,21 +161,6 @@ class Note
|
|||
];
|
||||
}
|
||||
|
||||
public static function parseVocabDef(string $vocabDef): ?array
|
||||
{
|
||||
if (mb_trim($vocabDef) === '') return null;
|
||||
|
||||
$terms = [];
|
||||
foreach (preg_split('|<br ?/?>|', $vocabDef) as $line) {
|
||||
$term = Term::fromVocabDefLine(strip_tags($line));
|
||||
// Error parsing term, can't parse using vocabDef
|
||||
if (null === $term) return null;
|
||||
$terms[] = $term;
|
||||
};
|
||||
|
||||
return $terms;
|
||||
}
|
||||
|
||||
public function parseMediaInfo(string $notes): ?array
|
||||
{
|
||||
$matches = null;
|
||||
|
|
|
@ -49,7 +49,7 @@ class Term
|
|||
return $ret;
|
||||
}
|
||||
|
||||
public static function fromVocabDefLine(string $vocabDefLine): ?Term
|
||||
private static function fromVocabDefLine(string $vocabDefLine): ?Term
|
||||
{
|
||||
$term = new Term();
|
||||
|
||||
|
@ -126,4 +126,19 @@ class Term
|
|||
|
||||
dd("Unexpected error, couldn't parse definition line", $vocabDefLine);
|
||||
}
|
||||
|
||||
public static function fromVocabDef(string $vocabDef): ?array
|
||||
{
|
||||
if (mb_trim($vocabDef) === '') return null;
|
||||
|
||||
$terms = [];
|
||||
foreach (preg_split('|<br ?/?>|', $vocabDef) as $line) {
|
||||
$term = self::fromVocabDefLine(strip_tags($line));
|
||||
// Error parsing term, can't parse using vocabDef
|
||||
if (null === $term) return null;
|
||||
$terms[] = $term;
|
||||
};
|
||||
|
||||
return $terms;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue