clear out clearVariables! In comes toXml

This commit is contained in:
felipe
2017-03-09 20:49:14 +01:00
parent 879b9163a3
commit 11e918114d
13 changed files with 26 additions and 141 deletions

View File

@ -5,9 +5,5 @@ export abstract class BaseXmlComponent {
this.rootKey = rootKey;
}
public abstract replaceKey(): void;
public clearVariables(): void {
// Do Nothing
}
public abstract toXml(): object;
}

View File

@ -16,15 +16,18 @@ export abstract class XmlAttributeComponent extends BaseXmlComponent {
}
}
public replaceKey(): void {
if (this.root !== undefined) {
public toXml(): object {
const attrs = {};
if (this.root != undefined) {
_.forOwn(this.root, (value, key) => {
const newKey = this.xmlKeys[key];
this.root[newKey] = value;
delete this.root[key];
if (value != undefined) {
const newKey = this.xmlKeys[key];
attrs[newKey] = value;
}
});
this[this.rootKey] = this.root;
delete this.root;
}
const ret = {};
ret[this.rootKey] = attrs;
return ret;
}
}

View File

@ -1,5 +1,6 @@
import * as _ from "lodash";
import { BaseXmlComponent } from "./base";
export { BaseXmlComponent };
export abstract class XmlComponent extends BaseXmlComponent {
protected root: Array<BaseXmlComponent | string>;
@ -9,17 +10,15 @@ export abstract class XmlComponent extends BaseXmlComponent {
this.root = new Array<BaseXmlComponent>();
}
public replaceKey(): void {
// console.log(this.rootKey);
// console.log(this.root);
if (this.root !== undefined) {
this.root.forEach((root) => {
if (root && root instanceof BaseXmlComponent) {
root.replaceKey();
}
});
this[this.rootKey] = this.root;
delete this.root;
public toXml(): object {
const ret = this.root.map((comp) => {
if (comp instanceof BaseXmlComponent) {
return comp.toXml();
}
return comp
}).filter((comp) => comp); // Exclude null, undefined, and empty strings
return {
[this.rootKey]: ret,
}
}
}