nodejs-rigorous
Version:
Rigorous Framework
41 lines (24 loc) • 969 B
JavaScript
const { RigorousError, errorTypes } = require('./RigorousError/index');
const h_format_checker = require('../helpers/h_format_checker');
module.exports = class ObjectScrapper {
constructor(scrapObject, imageNotFoundValue) {
if (!scrapObject) { throw new RigorousError(errorTypes.RESPONSE_ERROR_OBJECT_SCRAPPED_IS_NULL); }
this.imageNotFoundValue = imageNotFoundValue;
this.scrapObject = scrapObject;
}
setDefaultFieldValueIfNotFound(fieldName, fieldValue) {
const fieldVar = this.scrapObject[fieldName];
if (h_format_checker.isNil(fieldVar.v)) {
this.scrapObject[fieldName] = { v: fieldValue, s: 'not-found' };
}
}
getValue(fieldName) {
return this.scrapObject[fieldName].v;
}
getScrapperVersion() {
return this.scrapObject.scrapper_version;
}
hasImage() {
return this.getValue('image') !== this.imageNotFoundValue;
}
};