From dcdadb1608c07894b95df5b5e0b57bb813e7498a Mon Sep 17 00:00:00 2001 From: Adrian Short Date: Tue, 22 Jun 2021 14:18:20 +0100 Subject: [PATCH] Determine @system when Authority object is created This ensures that @system is set only once, avoiding bugs where any change to @url breaks subsequent calls to #system (as was). Improve Northgate detection by making it more specific, reducing false positives. --- lib/uk_planning_scraper/authority.rb | 29 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 15 deletions(-) diff --git a/lib/uk_planning_scraper/authority.rb b/lib/uk_planning_scraper/authority.rb index 9c2c14b..29be581 100644 --- a/lib/uk_planning_scraper/authority.rb +++ b/lib/uk_planning_scraper/authority.rb @@ -2,7 +2,7 @@ require 'csv' module UKPlanningScraper class Authority - attr_reader :name, :url + attr_reader :name, :url, :system @@authorities = [] @@ -12,6 +12,19 @@ module UKPlanningScraper @tags = [] # Strings in arbitrary order @applications = [] # Application objects @scrape_params = {} + + # Determine @system when Authority is created + if @url.match(/search\.do\?action=advanced/i) + @system = 'idox' + elsif @url.match(/generalsearch\.aspx/i) + @system = 'northgate' + elsif @url.match(/ocellaweb/i) + @system = 'ocellaweb' + elsif @url.match(/\/apas\//) + @system = 'agileplanning' + else + @system = 'unknownsystem' + end end def scrape(options = {}) @@ -67,20 +80,6 @@ module UKPlanningScraper @tags.include?(tag) end - def system - if @url.match(/search\.do\?action=advanced/i) - 'idox' - elsif @url.match(/\.aspx/i) - 'northgate' - elsif @url.match(/ocellaweb/i) - 'ocellaweb' - elsif @url.match(/\/apas\//) - 'agileplanning' - else - 'unknownsystem' - end - end - def self.all @@authorities end