Add StrainData Class
This commit is contained in:
parent
7321f4535b
commit
643eb0caa0
@ -46,6 +46,43 @@ module.exports = {
|
|||||||
this.content = typeof content === 'string' ? content : this.content;
|
this.content = typeof content === 'string' ? content : this.content;
|
||||||
this.iconUrl = typeof iconUrl === 'string' ? iconUrl : this.iconUrl;
|
this.iconUrl = typeof iconUrl === 'string' ? iconUrl : this.iconUrl;
|
||||||
|
|
||||||
|
return this; // For chaining
|
||||||
|
}
|
||||||
|
},
|
||||||
|
// StrainData
|
||||||
|
StrainData: class {
|
||||||
|
constructor() {
|
||||||
|
this.id = 0;
|
||||||
|
this.name = "";
|
||||||
|
this.type = "";
|
||||||
|
this.effects = "";
|
||||||
|
this.rating = "0.0";
|
||||||
|
}
|
||||||
|
|
||||||
|
// Initial Strain configuration
|
||||||
|
// Can also be used to update the data piecemeal
|
||||||
|
setInfo(name, details, id) {
|
||||||
|
/* details contains all the optional pieces of data
|
||||||
|
This is to prevent having to call setInfo(name, undefined, undefined, undefined, 0) or something
|
||||||
|
details: {
|
||||||
|
type: String,
|
||||||
|
effects: String,
|
||||||
|
rating: String
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
|
// Check for existing or incoming name
|
||||||
|
if ((this.name === "") && (typeof name !== 'string')) throw `Error: This Strain doesn't have existing name, and no name is going to be set.`;
|
||||||
|
|
||||||
|
// Property is set if the variable is the right type,
|
||||||
|
// otherwise it keeps the existing property
|
||||||
|
this.id = typeof id === 'number' ? id : this.id;
|
||||||
|
this.name = typeof name === 'string' ? name : this.name;
|
||||||
|
this.type = typeof details.type === 'string' ? details.type : this.type;
|
||||||
|
this.effects = typeof details.effects === 'string' ? details.effects : this.effects;
|
||||||
|
this.rating = typeof details.rating === 'string' ? details.rating : this.rating;
|
||||||
|
|
||||||
|
|
||||||
return this; // For chaining
|
return this; // For chaining
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user