From fa25e3c98392347213b2faa8eee0ca9544ad036a Mon Sep 17 00:00:00 2001 From: Jorge Bolois Guerrero Date: Sun, 21 Aug 2022 14:48:50 +0200 Subject: [PATCH] Adding garage. Adding missing house type. --- src/Item.js | 10 +++++++++- src/ItemHTML.js | 20 ++++++++++++++++++++ 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/src/Item.js b/src/Item.js index 2735f8b..3b77629 100644 --- a/src/Item.js +++ b/src/Item.js @@ -4,6 +4,7 @@ export default class Item { static NAME_SELECTOR = '.item-link'; static PRICE_SELECTOR = '.item-price'; + static GARAGE_SELECTOR = '.item-parking'; static ROOM_SELECTOR = '.item-detail-char .item-detail:nth-child(1)'; static METERS_SELECTOR = '.item-detail-char .item-detail:nth-child(2)'; @@ -18,6 +19,7 @@ export default class Item { this.priceMeter = this._extractPriceMeter(); this.additionalInfo = this._extractAdditionalInfo(); + this.hasGarage = this._extractGarage(); this.hasLift = this._extractLift(); this.isExterior = this._extractExterior(); this.isInterior = this._extractInterior(); @@ -61,9 +63,11 @@ export default class Item { isHouse() { return this._nameIncludes('Casa') - || this._nameIncludes('Chalet'); + || this._nameIncludes('Chalet') + || this._nameIncludes('Finca'); } + // TODO: This may be included in isFlat. isGround() { return this._nameIncludes('Bajo'); } @@ -116,4 +120,8 @@ export default class Item { return this.additionalInfo.includes('interior'); } + _extractGarage() { + return this._node.querySelector(Item.GARAGE_SELECTOR) !== null; + } + } \ No newline at end of file diff --git a/src/ItemHTML.js b/src/ItemHTML.js index 53073af..e3fd29a 100644 --- a/src/ItemHTML.js +++ b/src/ItemHTML.js @@ -27,6 +27,10 @@ export default class ItemHTML { return this.ERROR_CLASS_NAME; } + if (this._shouldCheckGarage() && !item.hasGarage) { + return this.ERROR_CLASS_NAME; + } + if (this._shouldCheckLift(item) && !item.hasLift) { return this.ERROR_CLASS_NAME; } @@ -43,6 +47,7 @@ export default class ItemHTML { ${this._createPercentagePriceHTML(item)} ${this._createPriceHTML(item)} ${this._createPriceMeterHTML(item)} + ${this._createGarageHTML(item)} ${this._createLiftHTML(item)} ${this._createExteriorHTML(item)} ` @@ -90,6 +95,21 @@ export default class ItemHTML { return this._createTextError('m²', item.priceMeter) } + static _createGarageHTML(item) { + if (!this._shouldCheckGarage()) { + return ``; + } + + if (item.hasGarage) { + return this._createSuccess('Garaje'); + } + return this._createError('Garaje'); + } + + static _shouldCheckGarage() { + return Preferences.get('garage'); + } + static _createLiftHTML(item) { if (!this._shouldCheckLift(item)) { return ``;