UNPKG

node-rigorous

Version:
44 lines (27 loc) 1.02 kB
const RigorousError = require('../facades/RigorousError'); const errorsMessages = require('../etc/errorsMessages'); const format_checker = require('../helpers/format_checker'); module.exports = class ObjectScrapper { constructor(scrapObject, imageNotFoundValue) { if (!scrapObject) { throw new RigorousError(errorsMessages.NullScrappedObjectError); } this.imageNotFoundValue = imageNotFoundValue; this.scrapObject = scrapObject; } setDefaultFieldValueIfNotFound(fieldName, fieldValue) { const fieldVar = this.scrapObject[fieldName]; if (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; } };