diff options
| author | Xinhui | 2016-11-29 15:09:54 +0100 |
|---|---|---|
| committer | Xinhui | 2016-11-29 15:52:39 +0100 |
| commit | bea0f42a318c17878fa99a0adaf3d3e2d2811a06 (patch) | |
| tree | 51d332b4630e5b1ad9afcdbdc6f1e20bd533275b | |
| parent | ac92d7020fe98f43381fc896a5c499e0029c7ac8 (diff) | |
| download | chouette-core-bea0f42a318c17878fa99a0adaf3d3e2d2811a06.tar.bz2 | |
Refactoring stop_area area_type as enumerize
| -rw-r--r-- | app/models/chouette/stop_area.rb | 4 | ||||
| -rw-r--r-- | config/locales/enumerize.en.yml | 8 | ||||
| -rw-r--r-- | config/locales/enumerize.fr.yml | 8 | ||||
| -rw-r--r-- | lib/stif/reflex_synchronization.rb | 15 | ||||
| -rw-r--r-- | spec/factories/chouette_stop_areas.rb | 2 | ||||
| -rw-r--r-- | spec/tasks/reflex_rake_spec.rb | 2 |
6 files changed, 32 insertions, 7 deletions
diff --git a/app/models/chouette/stop_area.rb b/app/models/chouette/stop_area.rb index 815304cca..2427d1694 100644 --- a/app/models/chouette/stop_area.rb +++ b/app/models/chouette/stop_area.rb @@ -7,6 +7,10 @@ class Chouette::StopArea < Chouette::ActiveRecord include Geokit::Mappable include ProjectionFields include StopAreaRestrictions + + extend Enumerize + enumerize :area_type, in: %i(zdep zder zdlp zdlr lda) + def self.model_name ActiveModel::Name.new self, Chouette, self.name.demodulize end diff --git a/config/locales/enumerize.en.yml b/config/locales/enumerize.en.yml index 2f865c9f1..b42f68003 100644 --- a/config/locales/enumerize.en.yml +++ b/config/locales/enumerize.en.yml @@ -85,7 +85,13 @@ en: cableway: Cableway funicular: Funicular other: Other - + stop_area: + area_type: + zdep: ZDEp + zder: ZDEr + zdlp: ZDLp + zdlr: ZDLr + lda: LDA line: transport_mode: interchange: Interchange diff --git a/config/locales/enumerize.fr.yml b/config/locales/enumerize.fr.yml index 33a987359..ecfde38bd 100644 --- a/config/locales/enumerize.fr.yml +++ b/config/locales/enumerize.fr.yml @@ -84,7 +84,13 @@ fr: cableway: Téléphérique funicular: Funiculaire other: Autre - + stop_area: + area_type: + zdep: ZDEp + zder: ZDEr + zdlp: ZDLp + zdlr: ZDLr + lda: LDA line: transport_mode: interchange: Interconnection diff --git a/lib/stif/reflex_synchronization.rb b/lib/stif/reflex_synchronization.rb index c62cbe94f..9408d2c7b 100644 --- a/lib/stif/reflex_synchronization.rb +++ b/lib/stif/reflex_synchronization.rb @@ -45,8 +45,9 @@ module Stif time = Benchmark.measure do stop_areas.each do |entry| next unless is_valid_type_of_place_ref?(method, entry) - self.processed << entry['id'] + entry['TypeOfPlaceRef'] = self.stop_area_area_type entry, method self.create_or_update_stop_area entry + self.processed << entry['id'] end end log_processing_time("Create or update StopArea", time.real) @@ -66,7 +67,15 @@ module Stif def is_valid_type_of_place_ref? method, entry return true if entry["TypeOfPlaceRef"].nil? return true if method == 'getOR' && ['ZDL', 'LDA', 'ZDE'].include?(entry["TypeOfPlaceRef"]) - return true if method == 'getOP' && ['ZDE'].include?(entry["TypeOfPlaceRef"]) + return true if method == 'getOP' && ['ZDE', 'ZDL'].include?(entry["TypeOfPlaceRef"]) + end + + def stop_area_area_type entry, method + type = entry['TypeOfPlaceRef'] + if type + type = "#{type}#{method.last}" unless type == 'LDA' + type.downcase + end end def set_deleted_stop_area @@ -128,7 +137,7 @@ module Stif stop.stop_area_referential = self.defaut_referential { :name => 'Name', - :area_type => 'type', + :area_type => 'TypeOfPlaceRef', :object_version => 'version', :zip_code => 'PostalRegion', :city_name => 'Town' diff --git a/spec/factories/chouette_stop_areas.rb b/spec/factories/chouette_stop_areas.rb index 5ac22adda..8e92b024b 100644 --- a/spec/factories/chouette_stop_areas.rb +++ b/spec/factories/chouette_stop_areas.rb @@ -3,7 +3,7 @@ FactoryGirl.define do sequence(:objectid) { |n| "test:StopArea:#{n}" } sequence(:name) { |n| "stop_area_#{n}" } sequence(:registration_number) { |n| "test-#{n}" } - area_type "CommercialStopPoint" + area_type { Chouette::StopArea.area_type.values.sample } latitude {10.0 * rand} longitude {10.0 * rand} diff --git a/spec/tasks/reflex_rake_spec.rb b/spec/tasks/reflex_rake_spec.rb index 7a27b49fc..ab1aefc7d 100644 --- a/spec/tasks/reflex_rake_spec.rb +++ b/spec/tasks/reflex_rake_spec.rb @@ -31,7 +31,7 @@ describe 'reflex:sync' do it 'should map xml data to StopArea attribute' do stop_area = Chouette::StopArea.find_by(objectid: 'FR:77153:LDA:69325:STIF') expect(stop_area.zip_code).to eq '77153' - expect(stop_area.area_type).to eq 'StopPlace' + expect(stop_area.area_type).to eq 'lda' end context 'On next sync' do |
