Ver código fonte

Flatten application hash

Instead of properties hashes within application hash we now prepends
the hash keys so the values are accessible at `property_1_uprn`...
pull/38/head
Graeme Porteous 5 anos atrás
pai
commit
779f0f8d91
1 arquivos alterados com 15 adições e 4 exclusões
  1. +15
    -4
      lib/uk_planning_scraper/application.rb

+ 15
- 4
lib/uk_planning_scraper/application.rb Ver arquivo

@@ -22,7 +22,7 @@ module UKPlanningScraper
attr_accessor :properties

def to_hash
{
base = {
scraped_at: @scraped_at,
authority_name: @authority_name,
council_reference: @council_reference,
@@ -39,10 +39,21 @@ module UKPlanningScraper
alternative_reference: @alternative_reference,
appeal_status: @appeal_status,
appeal_decision: @appeal_decision,
property_count: @property_count,
property_detail_urls: @property_detail_urls,
properties: @properties
property_count: @property_count
}

@property_detail_urls.each_with_index do |url, idx|
base["property_detail_url_#{idx + 1}".to_sym] = url
end if @property_detail_urls

@properties.each_with_index do |property, idx|
property_hash = property.to_hash
property_hash.transform_keys! { |k| "property_#{idx + 1}_#{k}".to_sym }

base.merge!(property_hash)
end if @properties

base
end

def valid?


Carregando…
Cancelar
Salvar