From 6921b8869fa6f5e087e008c76d6e60f4efbccf47 Mon Sep 17 00:00:00 2001 From: Alexandre Nunes Date: Sat, 19 Sep 2020 14:53:15 -0300 Subject: [PATCH] refactor: move mfenced vector case to external class --- .../mathml-tags/MFenced.ts | 32 ++++++++++++++----- 1 file changed, 24 insertions(+), 8 deletions(-) diff --git a/src/converters/mathml-interfaces-to-latex/mathml-tag-to-latex/mathml-tags/MFenced.ts b/src/converters/mathml-interfaces-to-latex/mathml-tag-to-latex/mathml-tags/MFenced.ts index 9ddc7a4..a76ada4 100755 --- a/src/converters/mathml-interfaces-to-latex/mathml-tag-to-latex/mathml-tags/MFenced.ts +++ b/src/converters/mathml-interfaces-to-latex/mathml-tag-to-latex/mathml-tags/MFenced.ts @@ -3,21 +3,37 @@ import { GenericWrapper } from '../../../../utils/wrappers'; import { JoinWithManySeparators } from '../../../../utils'; export class MFenced extends MathMLTag { - private _wrapper: GenericWrapper; - private _separators: string[]; + private readonly _open: string; + private readonly _close: string; + private readonly _separators: string[]; constructor(value: string, attributes: Record, children: MathMLTag[]) { super('mfenced', value, attributes, children); - const open: string = this._attributes.open || '('; - const close: string = this._attributes.close || ')'; - this._wrapper = new GenericWrapper(open, close); - + this._open = this._attributes.open || '('; + this._close = this._attributes.close || ')'; this._separators = Array.from(this._attributes.separators || ''); } convert(): string { - const withoutWrapper = JoinWithManySeparators.join(this._mapChildrenToLaTeX(), this._separators); - return this._wrapper.wrap(withoutWrapper); + return new Vector(this._open, this._close, this._separators).apply(this._mapChildrenToLaTeX()); + } +} + +class Vector { + private readonly _open: string; + private readonly _close: string; + private readonly _separators: string[]; + + constructor(open: string, close: string, separators: string[]) { + this._open = open; + this._close = close; + this._separators = separators; + } + + apply(latexContents: string[]): string { + const contentWithoutWrapper = JoinWithManySeparators.join(latexContents, this._separators); + + return new GenericWrapper(this._open, this._close).wrap(contentWithoutWrapper); } }