aboutsummaryrefslogtreecommitdiffstats
path: root/app/models/chouette/objectid
diff options
context:
space:
mode:
authorcedricnjanga2017-11-16 16:44:37 +0100
committerGuillaume2017-11-16 16:44:37 +0100
commit3f39b62beb9ff7af741696a6c3c7e87737c3a257 (patch)
treecbb89c8eb78fa9349bf499ffc01483d25554c3d0 /app/models/chouette/objectid
parente5fcb0cc0728cbb673c1f5cf346e865fbbbc593a (diff)
downloadchouette-core-3f39b62beb9ff7af741696a6c3c7e87737c3a257.tar.bz2
Add Cédric new objectid concerns
objectid_support handles reading and writing object_ids objectid_formater_support gets the right formater class include these concerns in chouette models Remove StifNetexAttributSupport modules because these are handled by the new objectid concerns Add a objectid and formater classes for each format type Add objectid formats to the factories Modify somes specs for object_ids but there are still a number of failling tests
Diffstat (limited to 'app/models/chouette/objectid')
-rw-r--r--app/models/chouette/objectid/netex.rb36
-rw-r--r--app/models/chouette/objectid/stif_codifligne.rb25
-rw-r--r--app/models/chouette/objectid/stif_netex.rb15
-rw-r--r--app/models/chouette/objectid/stif_reflex.rb24
4 files changed, 100 insertions, 0 deletions
diff --git a/app/models/chouette/objectid/netex.rb b/app/models/chouette/objectid/netex.rb
new file mode 100644
index 000000000..254ce6c6e
--- /dev/null
+++ b/app/models/chouette/objectid/netex.rb
@@ -0,0 +1,36 @@
+module Chouette
+ module Objectid
+ class Netex
+ include ActiveModel::Model
+
+ attr_accessor :provider_id, :object_type, :local_id, :creation_id
+ validates_presence_of :provider_id, :object_type, :local_id, :creation_id
+
+ def initialize(**attributes)
+ @provider_id ||= 'chouette'
+ @object_type = attributes[:object_type]
+ @local_id = attributes[:local_id]
+ @creation_id ||= 'LOC'
+ end
+
+ @@format = /^([A-Za-z_-]+):([A-Za-z]+):([0-9A-Za-z_-]+):([A-Za-z]+)$/
+ cattr_reader :format
+
+ def to_s
+ "#{self.provider_id}:#{self.object_type}:#{self.local_id}:#{self.creation_id}"
+ end
+
+ def parts
+ self.to_s.match(format).try(:captures)
+ end
+
+ def valid?
+ parts.present?
+ end
+
+ def short_id
+ local_id
+ end
+ end
+ end
+end
diff --git a/app/models/chouette/objectid/stif_codifligne.rb b/app/models/chouette/objectid/stif_codifligne.rb
new file mode 100644
index 000000000..9d83a1432
--- /dev/null
+++ b/app/models/chouette/objectid/stif_codifligne.rb
@@ -0,0 +1,25 @@
+module Chouette
+ module Objectid
+ class StifCodifligne < Chouette::Objectid::Netex
+
+ attr_accessor :sync_id
+ validates_presence_of :sync_id
+ validates :creation_id, presence: false
+
+ @@format = /^([A-Za-z_]+):([A-Za-z]+):([A-Za-z]+):([0-9A-Za-z_-]+)$/
+
+ def initialize(**attributes)
+ @provider_id = attributes[:provider_id]
+ @object_type = attributes[:object_type]
+ @local_id = attributes[:local_id]
+ @sync_id = attributes[:sync_id]
+ super
+ end
+
+ def to_s
+ "#{self.provider_id}:#{self.sync_id}:#{self.object_type}:#{self.local_id}"
+ end
+
+ end
+ end
+end
diff --git a/app/models/chouette/objectid/stif_netex.rb b/app/models/chouette/objectid/stif_netex.rb
new file mode 100644
index 000000000..e9d40a00f
--- /dev/null
+++ b/app/models/chouette/objectid/stif_netex.rb
@@ -0,0 +1,15 @@
+module Chouette
+ module Objectid
+ class StifNetex < Chouette::Objectid::Netex
+
+ def initialize(**attributes)
+ @provider_id = 'stif'
+ super
+ end
+
+ def short_id
+ local_id.try(:split, "-").try(:[], -1)
+ end
+ end
+ end
+end
diff --git a/app/models/chouette/objectid/stif_reflex.rb b/app/models/chouette/objectid/stif_reflex.rb
new file mode 100644
index 000000000..1ea3ec0ce
--- /dev/null
+++ b/app/models/chouette/objectid/stif_reflex.rb
@@ -0,0 +1,24 @@
+module Chouette
+ module Objectid
+ class StifReflex < Chouette::Objectid::Netex
+
+ attr_accessor :country_code, :zip_code
+ validates_presence_of :country_code, :zip_code
+ validates :creation_id, presence: false
+
+ @@format = /^([A-Za-z_]+):([0-9A-Za-z_-]+):([A-Za-z]+):([0-9A-Za-z_-]+):([A-Za-z]+)$/
+
+ def initialize(**attributes)
+ @provider_id = attributes[:provider_id]
+ @country_code = attributes[:country_code]
+ @zip_code = attributes[:zip_code]
+ super
+ end
+
+ def to_s
+ "#{self.country_code}:#{self.zip_code}:#{self.object_type}:#{self.local_id}:#{self.provider_id}"
+ end
+
+ end
+ end
+end