aboutsummaryrefslogtreecommitdiffstats
path: root/app/models/chouette/objectid/netex.rb
blob: 254ce6c6e1b9ff05cdb87d97bfb166be1badd836 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
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