aboutsummaryrefslogtreecommitdiffstats
path: root/app
diff options
context:
space:
mode:
authorcedricnjanga2017-11-24 17:06:52 +0100
committercedricnjanga2017-11-24 17:06:52 +0100
commitade8285b084529c09687e6995101b0aa651e2d4d (patch)
tree9ad1e0a9f24053cee93bfba04d58a87c428680e4 /app
parent9a08dc4d028f83e43a5fba83ebf09b68f21e9d49 (diff)
downloadchouette-core-ade8285b084529c09687e6995101b0aa651e2d4d.tar.bz2
Remove specs we dont need anymore
Diffstat (limited to 'app')
-rw-r--r--app/models/chouette/connection_link_type.rb58
-rw-r--r--app/models/chouette/direction.rb77
-rw-r--r--app/models/chouette/objectid/netex.rb6
-rw-r--r--app/models/chouette/objectid/stif_netex.rb4
-rw-r--r--app/models/chouette/objectid_formatter/netex.rb3
-rw-r--r--app/models/chouette/objectid_formatter/stif_netex.rb3
6 files changed, 73 insertions, 78 deletions
diff --git a/app/models/chouette/connection_link_type.rb b/app/models/chouette/connection_link_type.rb
index ce05c3ec4..516395ed9 100644
--- a/app/models/chouette/connection_link_type.rb
+++ b/app/models/chouette/connection_link_type.rb
@@ -1,11 +1,26 @@
module Chouette
class ConnectionLinkType < ActiveSupport::StringInquirer
-
def initialize(text_code, numerical_code)
super text_code.to_s
@numerical_code = numerical_code
end
+ def self.new(text_code, numerical_code = nil)
+ if text_code and numerical_code
+ super
+ elsif self === text_code
+ text_code
+ else
+ if Fixnum === text_code
+ text_code, numerical_code = definitions.rassoc(text_code)
+ else
+ text_code, numerical_code = definitions.assoc(text_code.to_s)
+ end
+
+ super text_code, numerical_code
+ end
+ end
+
def to_i
@numerical_code
end
@@ -18,37 +33,18 @@ module Chouette
camelize
end
- class << self
- attr_reader :definitions
- @definitions = [
- ["underground", 0],
- ["mixed", 1],
- ["overground", 2]
- ]
- @all = nil
-
- def new(text_code, numerical_code = nil)
- if text_code and numerical_code
- super
- elsif self === text_code
- text_code
- else
- if Fixnum === text_code
- text_code, numerical_code = definitions.rassoc(text_code)
- else
- text_code, numerical_code = definitions.assoc(text_code.to_s)
- end
-
- super text_code, numerical_code
- end
+ @@definitions = [
+ ["underground", 0],
+ ["mixed", 1],
+ ["overground", 2]
+ ]
+ cattr_reader :definitions
+
+ @@all = nil
+ def self.all
+ @@all ||= definitions.collect do |text_code, numerical_code|
+ new(text_code, numerical_code)
end
-
- def all
- @all ||= definitions.collect do |text_code, numerical_code|
- new(text_code, numerical_code)
- end
- end
-
end
end
end \ No newline at end of file
diff --git a/app/models/chouette/direction.rb b/app/models/chouette/direction.rb
index 13d3b87ce..2d3fea10a 100644
--- a/app/models/chouette/direction.rb
+++ b/app/models/chouette/direction.rb
@@ -1,11 +1,26 @@
module Chouette
class Direction < ActiveSupport::StringInquirer
-
def initialize(text_code, numerical_code)
super text_code.to_s
@numerical_code = numerical_code
end
+ def self.new(text_code, numerical_code = nil)
+ if text_code and numerical_code
+ super
+ elsif self === text_code
+ text_code
+ else
+ if Fixnum === text_code
+ text_code, numerical_code = definitions.rassoc(text_code)
+ else
+ text_code, numerical_code = definitions.assoc(text_code.to_s)
+ end
+
+ super text_code, numerical_code
+ end
+ end
+
def to_i
@numerical_code
end
@@ -18,47 +33,27 @@ module Chouette
to_s
end
- class << self
-
- attr_reader :definitions
- @definitions = [
- ["straight_forward", 0],
- ["backward", 1],
- ["clock_wise", 2],
- ["counter_clock_wise", 3],
- ["north", 4],
- ["north_west", 5],
- ["west", 6],
- ["south_west", 7],
- ["south", 8],
- ["south_east", 9],
- ["east", 10],
- ["north_east", 11]
- ]
- @all = nil
-
- def new(text_code, numerical_code = nil)
- if text_code and numerical_code
- super
- elsif self === text_code
- text_code
- else
- if Fixnum === text_code
- text_code, numerical_code = definitions.rassoc(text_code)
- else
- text_code, numerical_code = definitions.assoc(text_code.to_s)
- end
-
- super text_code, numerical_code
- end
+ @@definitions = [
+ ["straight_forward", 0],
+ ["backward", 1],
+ ["clock_wise", 2],
+ ["counter_clock_wise", 3],
+ ["north", 4],
+ ["north_west", 5],
+ ["west", 6],
+ ["south_west", 7],
+ ["south", 8],
+ ["south_east", 9],
+ ["east", 10],
+ ["north_east", 11]
+ ]
+ cattr_reader :definitions
+
+ @@all = nil
+ def self.all
+ @@all ||= definitions.collect do |text_code, numerical_code|
+ new(text_code, numerical_code)
end
-
- def all
- @all ||= definitions.collect do |text_code, numerical_code|
- new(text_code, numerical_code)
- end
- end
-
end
end
end \ No newline at end of file
diff --git a/app/models/chouette/objectid/netex.rb b/app/models/chouette/objectid/netex.rb
index 57415ac98..5d27abb1f 100644
--- a/app/models/chouette/objectid/netex.rb
+++ b/app/models/chouette/objectid/netex.rb
@@ -8,10 +8,10 @@ module Chouette
validate :must_respect_format
def initialize(**attributes)
- @provider_id ||= (attributes[:provider_id] ||= 'chouette')
+ @provider_id = attributes[:provider_id] || 'chouette'
@object_type = attributes[:object_type]
@local_id = attributes[:local_id]
- @creation_id = (attributes[:creation_id] ||= 'LOC')
+ @creation_id = attributes[:creation_id] || 'LOC'
end
@@format = /^([A-Za-z_-]+):([A-Za-z]+):([0-9A-Za-z_-]+):([A-Za-z]+)$/
@@ -22,7 +22,7 @@ module Chouette
end
def must_respect_format
- self.to_s.match(format)
+ self.to_s.match(self.class.format)
end
def short_id
diff --git a/app/models/chouette/objectid/stif_netex.rb b/app/models/chouette/objectid/stif_netex.rb
index 5bff21dbf..19fd42702 100644
--- a/app/models/chouette/objectid/stif_netex.rb
+++ b/app/models/chouette/objectid/stif_netex.rb
@@ -2,8 +2,10 @@ module Chouette
module Objectid
class StifNetex < Chouette::Objectid::Netex
+ @@format = Chouette::Objectid::Netex.format
+
def initialize(**attributes)
- @provider_id = (attributes[:provider_id] ||= 'stif')
+ @provider_id = attributes[:provider_id] ||= 'stif'
super
end
diff --git a/app/models/chouette/objectid_formatter/netex.rb b/app/models/chouette/objectid_formatter/netex.rb
index b8a903757..00c539553 100644
--- a/app/models/chouette/objectid_formatter/netex.rb
+++ b/app/models/chouette/objectid_formatter/netex.rb
@@ -2,7 +2,8 @@ module Chouette
module ObjectidFormatter
class Netex
def before_validation(model)
- model.update(objectid: Chouette::Objectid::Netex.new(local_id: SecureRandom.uuid, object_type: model.class.name.gsub('Chouette::','')).to_s)
+ oid = Chouette::Objectid::Netex.new(local_id: SecureRandom.uuid, object_type: model.class.name.gsub('Chouette::',''))
+ model.update(objectid: oid.to_s) if oid.valid?
end
def after_commit(model)
diff --git a/app/models/chouette/objectid_formatter/stif_netex.rb b/app/models/chouette/objectid_formatter/stif_netex.rb
index 4678cb337..01ddfc528 100644
--- a/app/models/chouette/objectid_formatter/stif_netex.rb
+++ b/app/models/chouette/objectid_formatter/stif_netex.rb
@@ -6,7 +6,8 @@ module Chouette
end
def after_commit(model)
- model.update(objectid: Chouette::Objectid::StifNetex.new(provider_id: "stif", object_type: model.class.name.gsub('Chouette::',''), local_id: model.local_id).to_s)
+ oid = Chouette::Objectid::StifNetex.new(provider_id: "stif", object_type: model.class.name.gsub('Chouette::',''), local_id: model.local_id)
+ model.update(objectid: oid.to_s) if oid.valid?
end
def get_objectid(definition)