diff options
Diffstat (limited to 'app/models/chouette/objectid')
| -rw-r--r-- | app/models/chouette/objectid/netex.rb | 36 | ||||
| -rw-r--r-- | app/models/chouette/objectid/stif_codifligne.rb | 25 | ||||
| -rw-r--r-- | app/models/chouette/objectid/stif_netex.rb | 15 | ||||
| -rw-r--r-- | app/models/chouette/objectid/stif_reflex.rb | 24 |
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 |
