aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMarc Florisson2015-06-11 08:30:25 +0200
committerMarc Florisson2015-06-11 08:30:25 +0200
commitb07ba1e6f22476d8c5d63e1babbf5d766100ea25 (patch)
tree0acb04f3ecbb2d9348e2799be060b1bba6896086
parent57b267d6bca0b570a4b3a2d3b5bf87a17ef878bb (diff)
downloadchouette-core-b07ba1e6f22476d8c5d63e1babbf5d766100ea25.tar.bz2
add extension for hub format
-rw-r--r--lib/ninoxe_extension/hub/company_restrictions.rb5
-rw-r--r--lib/ninoxe_extension/hub/group_of_line_restrictions.rb5
-rw-r--r--lib/ninoxe_extension/hub/journey_pattern_restrictions.rb5
-rw-r--r--lib/ninoxe_extension/hub/line_restrictions.rb7
-rw-r--r--lib/ninoxe_extension/hub/network_restrictions.rb5
-rw-r--r--lib/ninoxe_extension/hub/objectid_restrictions.rb23
-rw-r--r--lib/ninoxe_extension/hub/stop_area_restrictions.rb47
-rw-r--r--lib/ninoxe_extension/hub/time_table_restrictions.rb5
-rw-r--r--lib/ninoxe_extension/hub/vehicle_journey_restrictions.rb5
9 files changed, 72 insertions, 35 deletions
diff --git a/lib/ninoxe_extension/hub/company_restrictions.rb b/lib/ninoxe_extension/hub/company_restrictions.rb
index dd3f5efdf..190b63cd2 100644
--- a/lib/ninoxe_extension/hub/company_restrictions.rb
+++ b/lib/ninoxe_extension/hub/company_restrictions.rb
@@ -7,7 +7,7 @@ module NinoxeExtension::Hub
with_options if: :hub_restricted? do |g|
# HUB-7
- g.validates_format_of :objectid, :with => %r{\A\w+:\w+:[\w]{1,3}\z}
+ g.validate :specific_objectid
# HUB-8
g.validates_format_of :name, :with => %r{\A[\w]{1,75}\z}
# HUB-9
@@ -15,6 +15,9 @@ module NinoxeExtension::Hub
g.validates_uniqueness_of :registration_number
end
end
+ def specific_objectid
+ validate_specific_objectid( 3)
+ end
end
end
diff --git a/lib/ninoxe_extension/hub/group_of_line_restrictions.rb b/lib/ninoxe_extension/hub/group_of_line_restrictions.rb
index a386bb8ad..d5de71ce0 100644
--- a/lib/ninoxe_extension/hub/group_of_line_restrictions.rb
+++ b/lib/ninoxe_extension/hub/group_of_line_restrictions.rb
@@ -8,7 +8,7 @@ module NinoxeExtension::Hub
with_options if: :hub_restricted? do |g|
# HUB-11
- g.validates_format_of :objectid, :with => %r{\A\w+:\w+:[\w]{1,6}\z}
+ g.validate :specific_objectid
# HUB-12
g.validates_format_of :name, :with => %r{\A[\w]{1,75}\z}
# HUB-13
@@ -16,6 +16,9 @@ module NinoxeExtension::Hub
g.validates_uniqueness_of :registration_number
end
end
+ def specific_objectid
+ validate_specific_objectid( 6)
+ end
end
end
diff --git a/lib/ninoxe_extension/hub/journey_pattern_restrictions.rb b/lib/ninoxe_extension/hub/journey_pattern_restrictions.rb
index f5e04d5bb..448be9665 100644
--- a/lib/ninoxe_extension/hub/journey_pattern_restrictions.rb
+++ b/lib/ninoxe_extension/hub/journey_pattern_restrictions.rb
@@ -8,13 +8,16 @@ module NinoxeExtension::Hub
with_options if: :hub_restricted? do |jp|
# HUB-39
- jp.validates_format_of :objectid, :with => %r{\A\w+:\w+:[\w]{1,30}\z}
+ jp.validate :specific_objectid
# HUB-40
jp.validates :registration_number, :numericality => { :less_than => 10 ** 8 }
# HUB-41
jp.validates_format_of :name, :with => %r{\A[\w]{0,75}\z}
end
end
+ def specific_objectid
+ validate_specific_objectid( 30)
+ end
end
end
diff --git a/lib/ninoxe_extension/hub/line_restrictions.rb b/lib/ninoxe_extension/hub/line_restrictions.rb
index 03dbf675a..616d1fd52 100644
--- a/lib/ninoxe_extension/hub/line_restrictions.rb
+++ b/lib/ninoxe_extension/hub/line_restrictions.rb
@@ -9,7 +9,8 @@ module NinoxeExtension::Hub
with_options if: :hub_restricted? do |l|
# HUB-15
- l.validates_format_of :objectid, :with => %r{\A\w+:\w+:[\w]{1,14}\z}
+ #l.validates_format_of :objectid, :with => %r{\A\w+:\w+:[\w]{1,14}\z}
+ l.validate :specific_objectid
# HUB-16
l.validates_format_of :number, :with => %r{\A[\w]{1,6}\z}
# HUB-17
@@ -20,6 +21,10 @@ module NinoxeExtension::Hub
l.validates_uniqueness_of :name, :allow_blank => true
end
end
+
+ def specific_objectid
+ validate_specific_objectid( 14)
+ end
end
end
diff --git a/lib/ninoxe_extension/hub/network_restrictions.rb b/lib/ninoxe_extension/hub/network_restrictions.rb
index 58de2e8ab..7966736ec 100644
--- a/lib/ninoxe_extension/hub/network_restrictions.rb
+++ b/lib/ninoxe_extension/hub/network_restrictions.rb
@@ -7,7 +7,7 @@ module NinoxeExtension::Hub
with_options if: :hub_restricted? do |g|
# HUB-3
- g.validates_format_of :objectid, :with => %r{\A\w+:\w+:[\w]{1,3}\z}
+ g.validate :specific_objectid
# HUB-4
g.validates_format_of :name, :with => %r{\A[\w]{1,75}\z}
# HUB-5
@@ -15,6 +15,9 @@ module NinoxeExtension::Hub
g.validates_uniqueness_of :registration_number
end
end
+ def specific_objectid
+ validate_specific_objectid( 3)
+ end
end
end
diff --git a/lib/ninoxe_extension/hub/objectid_restrictions.rb b/lib/ninoxe_extension/hub/objectid_restrictions.rb
index 6f8608b49..a84e1428f 100644
--- a/lib/ninoxe_extension/hub/objectid_restrictions.rb
+++ b/lib/ninoxe_extension/hub/objectid_restrictions.rb
@@ -5,18 +5,25 @@ module NinoxeExtension::Hub::ObjectidRestrictions
included do
# HUB 1
validate :third_part_objectid_uniqueness
+ end
- def third_part_objectid
- self.objectid.match(/:(\w+)\z/)[1]
- end
- def third_part_objectid_uniqueness
- return unless hub_restricted?
+ def validate_specific_objectid( size_max )
+ errors.add( :objectid, I18n.t('hub.invalid')) if ( %r{\A\w+:\w+:\w+\z}).match( self.objectid).nil?
- return true unless third_part_objectid
- likes = Chouette::Line.where( "objectid LIKE ?", "%:#{self.third_part_objectid}" )
- likes.size.zero? || ( likes.size==1 && likes.first.id==self.id)
+ if third_part_objectid.nil? || ( !third_part_objectid.include?( "_pending_" ) && third_part_objectid.size > size_max)
+ errors.add( :objectid, I18n.t('hub.invalid'))
end
+ end
+ def third_part_objectid
+ return nil if ( %r{\A\w+:\w+:\w+\z}).match( self.objectid).nil?
+ self.objectid.match(/:(\w+)\z/)[1]
+ end
+ def third_part_objectid_uniqueness
+ return unless hub_restricted?
+ return true unless third_part_objectid
+ likes = Chouette::Line.where( "objectid LIKE ?", "%:#{self.third_part_objectid}" )
+ likes.size.zero? || ( likes.size==1 && likes.first.id==self.id)
end
end
diff --git a/lib/ninoxe_extension/hub/stop_area_restrictions.rb b/lib/ninoxe_extension/hub/stop_area_restrictions.rb
index 71b2b6323..8701c291c 100644
--- a/lib/ninoxe_extension/hub/stop_area_restrictions.rb
+++ b/lib/ninoxe_extension/hub/stop_area_restrictions.rb
@@ -3,36 +3,40 @@ module NinoxeExtension::Hub
module StopAreaRestrictions
extend ActiveSupport::Concern
+ def physical?
+ self.area_type=="BoardingPosition" || self.area_type=="Quay"
+ end
+ def commercial?
+ self.area_type=="CommercialStopPoint"
+ end
+ def physical_hub_restricted?
+ hub_restricted? && commercial?
+ end
+ def commercial_hub_restricted?
+ hub_restricted? && physical?
+ end
+ def commercial_and_physical_hub_restricted?
+ physical_hub_restricted? || commercial_hub_restricted?
+ end
+ def specific_objectid
+ validate_specific_objectid( 12)
+ end
+
included do
- #include ObjectidRestrictions
- def physical?
- self.area_type=="BoardingPosition" || self.area_type=="Quay"
- end
- def commercial?
- self.area_type=="CommercialStopPoint"
- end
- def self.physical_hub_restricted?
- Proc.new { |s| s.hub_restricted? && s.commercial?}
- end
- def self.commercial_hub_restricted?
- Proc.new { |s| s.hub_restricted? && s.physical?}
- end
- def self.commercial_and_physical_hub_restricted?
- physical_hub_restricted? || commercial_hub_restricted?
- end
+ include ObjectidRestrictions
- with_options if: commercial_and_physical_hub_restricted? do |sa|
+ with_options if: :commercial_and_physical_hub_restricted? do |sa|
# HUB-23
- sa.validates_format_of :objectid, :with => %r{\A\w+:\w+:[\w]{1,12}\z}
+ sa.validate :specific_objectid
sa.validates_format_of :name, :with => %r{\A[\w]{1,75}\z}
end
- with_options if: commercial_hub_restricted? do |sa|
+ with_options if: :commercial_hub_restricted? do |sa|
# HUB-24
validates_format_of :nearest_topic_name, :with => %r{\A[\w]{0,255}\z}
end
- with_options if: physical_hub_restricted? do |sa|
+ with_options if: :physical_hub_restricted? do |sa|
# HUB-25
sa.validates_format_of :nearest_topic_name, :with => %r{\A[\w]{0,60}\z}
# HUB-28
@@ -48,6 +52,9 @@ module NinoxeExtension::Hub
sa.validates_format_of :registration_number, :with => %r{\A[\w]{1,8}\z}, :allow_blank => true, :allow_nil => true
end
end
+ def specific_objectid
+ validate_specific_objectid( 12)
+ end
end
end
diff --git a/lib/ninoxe_extension/hub/time_table_restrictions.rb b/lib/ninoxe_extension/hub/time_table_restrictions.rb
index e771c296a..591810f42 100644
--- a/lib/ninoxe_extension/hub/time_table_restrictions.rb
+++ b/lib/ninoxe_extension/hub/time_table_restrictions.rb
@@ -8,11 +8,14 @@ module NinoxeExtension::Hub
with_options if: :hub_restricted? do |jp|
# HUB-44
- jp.validates_format_of :objectid, :with => %r{\A\w+:\w+:[\w]{1,6}\z}
+ jp.validate :specific_objectid
# HUB-45
jp.validates_format_of :comment, :with => %r{\A[\w]{0,75}\z}
end
end
+ def specific_objectid
+ validate_specific_objectid( 6)
+ end
end
end
diff --git a/lib/ninoxe_extension/hub/vehicle_journey_restrictions.rb b/lib/ninoxe_extension/hub/vehicle_journey_restrictions.rb
index 68112fc8f..151123a43 100644
--- a/lib/ninoxe_extension/hub/vehicle_journey_restrictions.rb
+++ b/lib/ninoxe_extension/hub/vehicle_journey_restrictions.rb
@@ -8,9 +8,12 @@ module NinoxeExtension::Hub
# HUB-42
with_options if: :hub_restricted? do |jp|
- jp.validates_format_of :objectid, :with => %r{\A\w+:\w+:[\w]{1,8}\z}
+ jp.validate :specific_objectid
end
end
+ def specific_objectid
+ validate_specific_objectid( 8)
+ end
end
end