diff options
Diffstat (limited to 'app/models/chouette/objectid')
| -rw-r--r-- | app/models/chouette/objectid/netex.rb | 33 | ||||
| -rw-r--r-- | app/models/chouette/objectid/stif_codifligne.rb | 28 | ||||
| -rw-r--r-- | app/models/chouette/objectid/stif_netex.rb | 17 | ||||
| -rw-r--r-- | app/models/chouette/objectid/stif_reflex.rb | 27 | 
4 files changed, 105 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..5d27abb1f --- /dev/null +++ b/app/models/chouette/objectid/netex.rb @@ -0,0 +1,33 @@ +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 +      validate :must_respect_format + +      def initialize(**attributes) +        @provider_id = attributes[:provider_id] || 'chouette' +        @object_type = attributes[:object_type] +        @local_id = attributes[:local_id] +        @creation_id = attributes[: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 must_respect_format +        self.to_s.match(self.class.format) +      end + +      def short_id +        local_id.try(:split, "-").try(:first) +      end +    end +  end +end
\ No newline at end of file diff --git a/app/models/chouette/objectid/stif_codifligne.rb b/app/models/chouette/objectid/stif_codifligne.rb new file mode 100644 index 000000000..903ebc2dc --- /dev/null +++ b/app/models/chouette/objectid/stif_codifligne.rb @@ -0,0 +1,28 @@ +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 + +      def short_id +        local_id +      end +    end +  end +end
\ No newline at end of file diff --git a/app/models/chouette/objectid/stif_netex.rb b/app/models/chouette/objectid/stif_netex.rb new file mode 100644 index 000000000..19fd42702 --- /dev/null +++ b/app/models/chouette/objectid/stif_netex.rb @@ -0,0 +1,17 @@ +module Chouette +  module Objectid +    class StifNetex < Chouette::Objectid::Netex + +      @@format = Chouette::Objectid::Netex.format + +      def initialize(**attributes) +        @provider_id = attributes[:provider_id] ||= 'stif' +        super +      end + +      def short_id +        local_id.try(:split, "-").try(:last) +      end +    end +  end +end
\ No newline at end of file diff --git a/app/models/chouette/objectid/stif_reflex.rb b/app/models/chouette/objectid/stif_reflex.rb new file mode 100644 index 000000000..770f3c433 --- /dev/null +++ b/app/models/chouette/objectid/stif_reflex.rb @@ -0,0 +1,27 @@ +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 + +      def short_id +        local_id +      end +    end +  end +end
\ No newline at end of file  | 
