diff options
Diffstat (limited to 'app/models/chouette/object_id.rb')
| -rw-r--r-- | app/models/chouette/object_id.rb | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/app/models/chouette/object_id.rb b/app/models/chouette/object_id.rb new file mode 100644 index 000000000..4f58048e1 --- /dev/null +++ b/app/models/chouette/object_id.rb @@ -0,0 +1,36 @@ +class Chouette::ObjectId < String + + def valid? + parts.present? + end + alias_method :objectid?, :valid? + + @@format = /^([0-9A-Za-z_]+):([A-Za-z]+):([0-9A-Za-z_-]+)$/ + cattr_reader :format + + def parts + match(format).try(:captures) + end + + def system_id + parts.try(:first) + end + + def object_type + parts.try(:second) + end + + def local_id + parts.try(:third) + end + + def self.create(system_id, object_type, local_id) + new [system_id, object_type, local_id].join(":") + end + + def self.new(string) + string ||= "" + self === string ? string : super + end + +end |
