ninoxe 0.0.8
Sign up to get free protection for your applications and to get access to all the features.
- data/MIT-LICENSE +20 -0
- data/README.rdoc +3 -0
- data/Rakefile +49 -0
- data/app/assets/javascripts/ninoxe/application.js +15 -0
- data/app/assets/stylesheets/ninoxe/application.css +13 -0
- data/app/controllers/ninoxe/application_controller.rb +4 -0
- data/app/helpers/ninoxe/application_helper.rb +4 -0
- data/app/models/chouette/access_link.rb +63 -0
- data/app/models/chouette/access_point.rb +145 -0
- data/app/models/chouette/access_point_type.rb +50 -0
- data/app/models/chouette/active_record.rb +66 -0
- data/app/models/chouette/area_type.rb +56 -0
- data/app/models/chouette/chouette_structure.dump +3417 -0
- data/app/models/chouette/command.rb +93 -0
- data/app/models/chouette/command_line_support.rb +35 -0
- data/app/models/chouette/company.rb +19 -0
- data/app/models/chouette/connection_link.rb +43 -0
- data/app/models/chouette/connection_link_type.rb +51 -0
- data/app/models/chouette/direction.rb +60 -0
- data/app/models/chouette/exporter.rb +32 -0
- data/app/models/chouette/file_validator.rb +47 -0
- data/app/models/chouette/group_of_line.rb +30 -0
- data/app/models/chouette/journey_pattern.rb +63 -0
- data/app/models/chouette/line.rb +65 -0
- data/app/models/chouette/link_orientation_type.rb +49 -0
- data/app/models/chouette/loader.rb +110 -0
- data/app/models/chouette/network.rb +33 -0
- data/app/models/chouette/object_id.rb +36 -0
- data/app/models/chouette/pt_link.rb +39 -0
- data/app/models/chouette/route.rb +158 -0
- data/app/models/chouette/stop_area.rb +273 -0
- data/app/models/chouette/stop_point.rb +33 -0
- data/app/models/chouette/time_table.rb +146 -0
- data/app/models/chouette/time_table_date.rb +14 -0
- data/app/models/chouette/time_table_period.rb +26 -0
- data/app/models/chouette/time_table_vehicle_journey.rb +5 -0
- data/app/models/chouette/transport_mode.rb +71 -0
- data/app/models/chouette/trident_active_record.rb +97 -0
- data/app/models/chouette/vehicle_journey.rb +101 -0
- data/app/models/chouette/vehicle_journey_at_stop.rb +45 -0
- data/app/models/chouette/wayback.rb +50 -0
- data/app/views/layouts/ninoxe/application.html.erb +14 -0
- data/config/database.yml +9 -0
- data/config/database.yml.ci +14 -0
- data/config/database.yml.travis +9 -0
- data/config/locales/en.yml +15 -0
- data/config/locales/fr.yml +16 -0
- data/config/routes.rb +2 -0
- data/db/migrate/20120213131553_create_chouette_line.rb +26 -0
- data/db/migrate/20120214101458_create_chouette_company.rb +25 -0
- data/db/migrate/20120214101645_create_chouette_ptnetwork.rb +24 -0
- data/db/migrate/20120406144221_create_chouette_stop_area.rb +33 -0
- data/db/migrate/20120411144209_create_time_table.rb +38 -0
- data/db/migrate/20120425064403_create_chouette_route.rb +22 -0
- data/db/migrate/20120425123944_create_chouette_stop_point.rb +17 -0
- data/db/migrate/20120426114527_create_chouette_connection_link.rb +28 -0
- data/db/migrate/20120521073709_create_chouette_journey_pattern.rb +26 -0
- data/db/migrate/20120521073723_create_chouette_journey_pattern_stop_point.rb +14 -0
- data/db/migrate/20120521073740_create_chouette_time_slot.rb +22 -0
- data/db/migrate/20120521073746_create_chouette_vehicle_journey.rb +34 -0
- data/db/migrate/20120521073758_create_chouette_vehicle_journey_at_stop.rb +25 -0
- data/db/migrate/20120521073900_create_chouette_time_table_vehicle_journey.rb +16 -0
- data/db/migrate/20120521132304_create_chouette_access_point.rb +34 -0
- data/db/migrate/20120521132313_create_chouette_access_link.rb +33 -0
- data/db/migrate/20120521132429_create_chouette_facility.rb +34 -0
- data/db/migrate/20120521132502_create_chouette_facility_feature.rb +12 -0
- data/db/migrate/20120521132551_create_chouette_group_of_line.rb +18 -0
- data/db/migrate/20120521132600_create_chouette_group_of_line_line.rb +12 -0
- data/db/migrate/20120521132656_create_chouette_routing_constrains_line.rb +12 -0
- data/db/migrate/20120521132724_create_chouette_stoparea_stoparea.rb +12 -0
- data/db/migrate/20120531091529_create_chouette_pt_link.rb +21 -0
- data/db/migrate/20120926141405_add_id_to_time_table_date.rb +12 -0
- data/db/migrate/20120926141415_add_id_to_time_table_period.rb +12 -0
- data/db/migrate/20121024072219_add_fields_to_access_points.rb +12 -0
- data/lib/chouette_factories.rb +1 -0
- data/lib/factories/chouette_access_links.rb +11 -0
- data/lib/factories/chouette_access_points.rb +8 -0
- data/lib/factories/chouette_companies.rb +5 -0
- data/lib/factories/chouette_connection_links.rb +11 -0
- data/lib/factories/chouette_group_of_lines.rb +4 -0
- data/lib/factories/chouette_journey_pattern.rb +32 -0
- data/lib/factories/chouette_lines.rb +20 -0
- data/lib/factories/chouette_networks.rb +5 -0
- data/lib/factories/chouette_routes.rb +18 -0
- data/lib/factories/chouette_stop_areas.rb +8 -0
- data/lib/factories/chouette_stop_points.rb +7 -0
- data/lib/factories/chouette_time_table.rb +21 -0
- data/lib/factories/chouette_vehicle_journey.rb +50 -0
- data/lib/factories/chouette_vehicle_journey_at_stop.rb +5 -0
- data/lib/ninoxe/engine.rb +15 -0
- data/lib/ninoxe/version.rb +3 -0
- data/lib/ninoxe.rb +7 -0
- metadata +251 -0
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright 2012 YOURNAME
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.rdoc
ADDED
data/Rakefile
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
#!/usr/bin/env rake
|
2
|
+
begin
|
3
|
+
require 'bundler/setup'
|
4
|
+
rescue LoadError
|
5
|
+
puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
|
6
|
+
end
|
7
|
+
|
8
|
+
APP_RAKEFILE = File.expand_path("../spec/dummy/Rakefile", __FILE__)
|
9
|
+
load 'rails/tasks/engine.rake'
|
10
|
+
|
11
|
+
Bundler::GemHelper.install_tasks
|
12
|
+
|
13
|
+
namespace :ci do
|
14
|
+
task :prepare do
|
15
|
+
cp "config/database.yml.ci", "config/database.yml"
|
16
|
+
end
|
17
|
+
task :travis do
|
18
|
+
cp "config/database.yml.travis", "config/database.yml"
|
19
|
+
end
|
20
|
+
task :build => ["db:migrate", "spec"]
|
21
|
+
end
|
22
|
+
|
23
|
+
begin
|
24
|
+
require 'rdoc/task'
|
25
|
+
rescue LoadError
|
26
|
+
require 'rdoc/rdoc'
|
27
|
+
require 'rake/rdoctask'
|
28
|
+
RDoc::Task = Rake::RDocTask
|
29
|
+
end
|
30
|
+
|
31
|
+
RDoc::Task.new(:rdoc) do |rdoc|
|
32
|
+
rdoc.rdoc_dir = 'rdoc'
|
33
|
+
rdoc.title = 'Ninoxe'
|
34
|
+
rdoc.options << '--line-numbers'
|
35
|
+
rdoc.rdoc_files.include('README.rdoc')
|
36
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
37
|
+
end
|
38
|
+
|
39
|
+
require 'rspec/core'
|
40
|
+
require 'rspec/core/rake_task'
|
41
|
+
|
42
|
+
RSpec::Core::RakeTask.new(:spec)
|
43
|
+
|
44
|
+
task :spec => "app:db:test:prepare"
|
45
|
+
|
46
|
+
RSpec::Core::RakeTask.new(:rcov) do |t|
|
47
|
+
t.rcov = true
|
48
|
+
t.rcov_opts = %w{--exclude osx\/objc,gems\/,spec\/,lib\/database_cleaner\/}
|
49
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
// This is a manifest file that'll be compiled into application.js, which will include all the files
|
2
|
+
// listed below.
|
3
|
+
//
|
4
|
+
// Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
|
5
|
+
// or vendor/assets/javascripts of plugins, if any, can be referenced here using a relative path.
|
6
|
+
//
|
7
|
+
// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
|
8
|
+
// the compiled file.
|
9
|
+
//
|
10
|
+
// WARNING: THE FIRST BLANK LINE MARKS THE END OF WHAT'S TO BE PROCESSED, ANY BLANK LINE SHOULD
|
11
|
+
// GO AFTER THE REQUIRES BELOW.
|
12
|
+
//
|
13
|
+
//= require jquery
|
14
|
+
//= require jquery_ujs
|
15
|
+
//= require_tree .
|
@@ -0,0 +1,13 @@
|
|
1
|
+
/*
|
2
|
+
* This is a manifest file that'll be compiled into application.css, which will include all the files
|
3
|
+
* listed below.
|
4
|
+
*
|
5
|
+
* Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
|
6
|
+
* or vendor/assets/stylesheets of plugins, if any, can be referenced here using a relative path.
|
7
|
+
*
|
8
|
+
* You're free to add application-wide styles to this file and they'll appear at the top of the
|
9
|
+
* compiled file, but it's generally better to create a new file per style scope.
|
10
|
+
*
|
11
|
+
*= require_self
|
12
|
+
*= require_tree .
|
13
|
+
*/
|
@@ -0,0 +1,63 @@
|
|
1
|
+
class Chouette::AccessLink < Chouette::TridentActiveRecord
|
2
|
+
# FIXME http://jira.codehaus.org/browse/JRUBY-6358
|
3
|
+
set_primary_key :id
|
4
|
+
|
5
|
+
attr_accessor :access_link_type, :link_orientation_type, :link_key
|
6
|
+
|
7
|
+
attr_accessible :id, :access_link_type,:access_point_id, :stop_area_id
|
8
|
+
attr_accessible :objectid, :object_version, :creation_time, :creator_id, :name, :comment
|
9
|
+
attr_accessible :link_distance, :link_type, :default_duration, :frequent_traveller_duration, :occasional_traveller_duration
|
10
|
+
attr_accessible :mobility_restricted_traveller_duration, :mobility_restricted_suitability, :stairs_availability, :lift_availability, :int_user_needs
|
11
|
+
attr_accessible :link_orientation
|
12
|
+
attr_accessible :link_orientation_type, :stop_area
|
13
|
+
|
14
|
+
belongs_to :access_point, :class_name => 'Chouette::AccessPoint'
|
15
|
+
belongs_to :stop_area, :class_name => 'Chouette::StopArea'
|
16
|
+
|
17
|
+
validates_presence_of :name
|
18
|
+
validates_presence_of :link_type
|
19
|
+
validates_presence_of :link_orientation
|
20
|
+
|
21
|
+
def access_link_type
|
22
|
+
link_type && Chouette::ConnectionLinkType.new(link_type.underscore)
|
23
|
+
end
|
24
|
+
|
25
|
+
def access_link_type=(access_link_type)
|
26
|
+
self.link_type = (access_link_type ? access_link_type.camelcase : nil)
|
27
|
+
end
|
28
|
+
|
29
|
+
@@access_link_types = nil
|
30
|
+
def self.access_link_types
|
31
|
+
@@access_link_types ||= Chouette::ConnectionLinkType.all
|
32
|
+
end
|
33
|
+
|
34
|
+
def link_orientation_type
|
35
|
+
link_orientation && Chouette::LinkOrientationType.new(link_orientation.underscore)
|
36
|
+
end
|
37
|
+
|
38
|
+
def link_orientation_type=(link_orientation_type)
|
39
|
+
self.link_orientation = (link_orientation_type ? link_orientation_type.camelcase : nil)
|
40
|
+
end
|
41
|
+
|
42
|
+
@@link_orientation_types = nil
|
43
|
+
def self.link_orientation_types
|
44
|
+
@@link_orientation_types ||= Chouette::LinkOrientationType.all
|
45
|
+
end
|
46
|
+
|
47
|
+
def geometry
|
48
|
+
GeoRuby::SimpleFeatures::LineString.from_points( [ access_point.geometry, stop_area.geometry], 4326) if access_point.geometry and stop_area.geometry
|
49
|
+
end
|
50
|
+
|
51
|
+
def link_key
|
52
|
+
Chouette::AccessLink.build_link_key(access_point,stop_area,link_orientation_type)
|
53
|
+
end
|
54
|
+
|
55
|
+
def self.build_link_key(access_point,stop_area,link_orientation_type)
|
56
|
+
if link_orientation_type == "access_point_to_stop_area"
|
57
|
+
"A_#{access_point.id}-S_#{stop_area.id}"
|
58
|
+
else
|
59
|
+
"S_#{stop_area.id}-A_#{access_point.id}"
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
@@ -0,0 +1,145 @@
|
|
1
|
+
require 'geokit'
|
2
|
+
require 'geo_ruby'
|
3
|
+
|
4
|
+
class Chouette::AccessPoint < Chouette::TridentActiveRecord
|
5
|
+
# FIXME http://jira.codehaus.org/browse/JRUBY-6358
|
6
|
+
set_primary_key :id
|
7
|
+
include Geokit::Mappable
|
8
|
+
has_many :access_links, :dependent => :destroy
|
9
|
+
belongs_to :stop_area
|
10
|
+
|
11
|
+
attr_accessor :access_point_type
|
12
|
+
attr_accessible :objectid, :object_version, :creation_time, :creator_id, :name, :comment
|
13
|
+
attr_accessible :longitude, :latitude, :long_lat_type, :x, :y, :projection_type
|
14
|
+
attr_accessible :country_code, :street_name
|
15
|
+
attr_accessible :openning_time, :closing_time, :access_type, :access_point_type
|
16
|
+
attr_accessible :mobility_restricted_suitability, :stairs_availability, :lift_availability
|
17
|
+
attr_accessible :stop_area_id
|
18
|
+
|
19
|
+
# workaround of ruby 1.8 private method y block attribute y reading access
|
20
|
+
def y
|
21
|
+
read_attribute :y
|
22
|
+
end
|
23
|
+
|
24
|
+
validates_presence_of :name
|
25
|
+
validates_presence_of :access_type
|
26
|
+
|
27
|
+
validates_presence_of :latitude, :if => :longitude
|
28
|
+
validates_presence_of :longitude, :if => :latitude
|
29
|
+
validates_numericality_of :latitude, :less_than_or_equal_to => 90, :greater_than_or_equal_to => -90, :allow_nil => true
|
30
|
+
validates_numericality_of :longitude, :less_than_or_equal_to => 180, :greater_than_or_equal_to => -180, :allow_nil => true
|
31
|
+
|
32
|
+
validates_presence_of :x, :if => :y
|
33
|
+
validates_presence_of :y, :if => :x
|
34
|
+
validates_numericality_of :x, :allow_nil => true
|
35
|
+
validates_numericality_of :y, :allow_nil => true
|
36
|
+
|
37
|
+
def self.nullable_attributes
|
38
|
+
[:street_name, :country_code, :comment, :projection_type, :long_lat_type, :x, :y]
|
39
|
+
end
|
40
|
+
|
41
|
+
def to_lat_lng
|
42
|
+
Geokit::LatLng.new(latitude, longitude) if latitude and longitude
|
43
|
+
end
|
44
|
+
|
45
|
+
def geometry
|
46
|
+
GeoRuby::SimpleFeatures::Point.from_lon_lat(longitude, latitude, 4326) if latitude and longitude
|
47
|
+
end
|
48
|
+
|
49
|
+
def geometry=(geometry)
|
50
|
+
geometry = geometry.to_wgs84
|
51
|
+
self.latitude, self.longitude, self.long_lat_type = geometry.lat, geometry.lng, "WGS84"
|
52
|
+
end
|
53
|
+
|
54
|
+
def position
|
55
|
+
geometry
|
56
|
+
end
|
57
|
+
|
58
|
+
def position=(position)
|
59
|
+
position = nil if String === position && position == ""
|
60
|
+
position = Geokit::LatLng.normalize(position), 4326 if String === position
|
61
|
+
self.latitude = position.lat
|
62
|
+
self.longitude = position.lng
|
63
|
+
end
|
64
|
+
|
65
|
+
def default_position
|
66
|
+
stop_area.geometry or stop_area.default_position
|
67
|
+
end
|
68
|
+
|
69
|
+
|
70
|
+
def access_point_type
|
71
|
+
access_type && Chouette::AccessPointType.new(access_type.underscore)
|
72
|
+
end
|
73
|
+
|
74
|
+
def access_point_type=(access_point_type)
|
75
|
+
self.access_type = (access_point_type ? access_point_type.camelcase : nil)
|
76
|
+
end
|
77
|
+
|
78
|
+
@@access_point_types = nil
|
79
|
+
def self.access_point_types
|
80
|
+
@@access_point_types ||= Chouette::AccessPointType.all.select do |access_point_type|
|
81
|
+
access_point_type.to_i >= 0
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
def generic_access_link_matrix
|
86
|
+
matrix = Array.new
|
87
|
+
hash = Hash.new
|
88
|
+
access_links.each do |link|
|
89
|
+
hash[link.link_key] = link
|
90
|
+
end
|
91
|
+
key=Chouette::AccessLink.build_link_key(self,stop_area,"access_point_to_stop_area")
|
92
|
+
if hash.has_key?(key)
|
93
|
+
matrix << hash[key]
|
94
|
+
else
|
95
|
+
link = Chouette::AccessLink.new
|
96
|
+
link.access_point = self
|
97
|
+
link.stop_area = stop_area
|
98
|
+
link.link_orientation_type = "access_point_to_stop_area"
|
99
|
+
matrix << link
|
100
|
+
end
|
101
|
+
key=Chouette::AccessLink.build_link_key(self,stop_area,"stop_area_to_access_point")
|
102
|
+
if hash.has_key?(key)
|
103
|
+
matrix << hash[key]
|
104
|
+
else
|
105
|
+
link = Chouette::AccessLink.new
|
106
|
+
link.access_point = self
|
107
|
+
link.stop_area = stop_area
|
108
|
+
link.link_orientation_type = "stop_area_to_access_point"
|
109
|
+
matrix << link
|
110
|
+
end
|
111
|
+
matrix
|
112
|
+
end
|
113
|
+
|
114
|
+
def detail_access_link_matrix
|
115
|
+
matrix = Array.new
|
116
|
+
hash = Hash.new
|
117
|
+
access_links.each do |link|
|
118
|
+
hash[link.link_key] = link
|
119
|
+
end
|
120
|
+
stop_area.children_at_base.each do |child|
|
121
|
+
key=Chouette::AccessLink.build_link_key(self,child,"access_point_to_stop_area")
|
122
|
+
if hash.has_key?(key)
|
123
|
+
matrix << hash[key]
|
124
|
+
else
|
125
|
+
link = Chouette::AccessLink.new
|
126
|
+
link.access_point = self
|
127
|
+
link.stop_area = child
|
128
|
+
link.link_orientation_type = "access_point_to_stop_area"
|
129
|
+
matrix << link
|
130
|
+
end
|
131
|
+
key=Chouette::AccessLink.build_link_key(self,child,"stop_area_to_access_point")
|
132
|
+
if hash.has_key?(key)
|
133
|
+
matrix << hash[key]
|
134
|
+
else
|
135
|
+
link = Chouette::AccessLink.new
|
136
|
+
link.access_point = self
|
137
|
+
link.stop_area = child
|
138
|
+
link.link_orientation_type = "stop_area_to_access_point"
|
139
|
+
matrix << link
|
140
|
+
end
|
141
|
+
end
|
142
|
+
matrix
|
143
|
+
end
|
144
|
+
|
145
|
+
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
class Chouette::AccessPointType < ActiveSupport::StringInquirer
|
2
|
+
|
3
|
+
def initialize(text_code, numerical_code)
|
4
|
+
super text_code.to_s
|
5
|
+
@numerical_code = numerical_code
|
6
|
+
end
|
7
|
+
|
8
|
+
def self.new(text_code, numerical_code = nil)
|
9
|
+
if text_code and numerical_code
|
10
|
+
super
|
11
|
+
elsif self === text_code
|
12
|
+
text_code
|
13
|
+
else
|
14
|
+
if Fixnum === text_code
|
15
|
+
text_code, numerical_code = definitions.rassoc(text_code)
|
16
|
+
else
|
17
|
+
text_code, numerical_code = definitions.assoc(text_code.to_s)
|
18
|
+
end
|
19
|
+
|
20
|
+
super text_code, numerical_code
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
def to_i
|
25
|
+
@numerical_code
|
26
|
+
end
|
27
|
+
|
28
|
+
def inspect
|
29
|
+
"#{to_s}/#{to_i}"
|
30
|
+
end
|
31
|
+
|
32
|
+
def name
|
33
|
+
camelize
|
34
|
+
end
|
35
|
+
|
36
|
+
@@definitions = [
|
37
|
+
["in", 0],
|
38
|
+
["out", 1],
|
39
|
+
["in_out", 2]
|
40
|
+
]
|
41
|
+
cattr_reader :definitions
|
42
|
+
|
43
|
+
@@all = nil
|
44
|
+
def self.all
|
45
|
+
@@all ||= definitions.collect do |text_code, numerical_code|
|
46
|
+
new(text_code, numerical_code)
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
end
|
@@ -0,0 +1,66 @@
|
|
1
|
+
#require "active_record"
|
2
|
+
|
3
|
+
module Chouette
|
4
|
+
class ActiveRecord < ::ActiveRecord::Base
|
5
|
+
|
6
|
+
self.abstract_class = true
|
7
|
+
|
8
|
+
before_save :nil_if_blank
|
9
|
+
|
10
|
+
# to be overrided to set nullable attrs when empty
|
11
|
+
def self.nullable_attributes
|
12
|
+
[]
|
13
|
+
end
|
14
|
+
|
15
|
+
def nil_if_blank
|
16
|
+
self.class.nullable_attributes.each { |attr| self[attr] = nil if self[attr].blank? }
|
17
|
+
end
|
18
|
+
|
19
|
+
|
20
|
+
def human_attribute_name(*args)
|
21
|
+
self.class.human_attribute_name(*args)
|
22
|
+
end
|
23
|
+
|
24
|
+
class << self
|
25
|
+
alias_method :create_reflection_without_chouette_naming, :create_reflection
|
26
|
+
|
27
|
+
def create_reflection(macro, name, options, active_record)
|
28
|
+
options =
|
29
|
+
Reflection.new(macro, name, options, active_record).options_with_default
|
30
|
+
|
31
|
+
create_reflection_without_chouette_naming(macro, name, options, active_record)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
|
36
|
+
|
37
|
+
class Reflection
|
38
|
+
|
39
|
+
attr_reader :macro, :name, :options, :active_record
|
40
|
+
|
41
|
+
def initialize(macro, name, options, active_record)
|
42
|
+
@macro, @name, @options, @active_record = macro, name.to_s, options, active_record
|
43
|
+
end
|
44
|
+
|
45
|
+
def collection?
|
46
|
+
macro == :has_many
|
47
|
+
end
|
48
|
+
|
49
|
+
def singular_name
|
50
|
+
collection? ? name.singularize : name
|
51
|
+
end
|
52
|
+
|
53
|
+
def class_name
|
54
|
+
"Chouette::#{singular_name.camelize}"
|
55
|
+
end
|
56
|
+
|
57
|
+
def options_with_default
|
58
|
+
options.dup.tap do |options|
|
59
|
+
options[:class_name] ||= class_name
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
end
|
64
|
+
|
65
|
+
end
|
66
|
+
end
|
@@ -0,0 +1,56 @@
|
|
1
|
+
class Chouette::AreaType < ActiveSupport::StringInquirer
|
2
|
+
|
3
|
+
def initialize(text_code, numerical_code)
|
4
|
+
super text_code.to_s
|
5
|
+
@numerical_code = numerical_code
|
6
|
+
end
|
7
|
+
|
8
|
+
def self.new(text_code, numerical_code = nil)
|
9
|
+
if text_code and numerical_code
|
10
|
+
super
|
11
|
+
elsif self === text_code
|
12
|
+
text_code
|
13
|
+
else
|
14
|
+
if Fixnum === text_code
|
15
|
+
text_code, numerical_code = definitions.rassoc(text_code)
|
16
|
+
else
|
17
|
+
text_code, numerical_code = definitions.assoc(text_code.to_s)
|
18
|
+
end
|
19
|
+
|
20
|
+
super text_code, numerical_code
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
def to_i
|
25
|
+
@numerical_code
|
26
|
+
end
|
27
|
+
|
28
|
+
def inspect
|
29
|
+
"#{to_s}/#{to_i}"
|
30
|
+
end
|
31
|
+
|
32
|
+
def name
|
33
|
+
if (to_s == 'itl')
|
34
|
+
to_s.upcase
|
35
|
+
else
|
36
|
+
camelize
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
@@definitions = [
|
41
|
+
["boarding_position", 0],
|
42
|
+
["quay", 1],
|
43
|
+
["commercial_stop_point", 2],
|
44
|
+
["stop_place", 3],
|
45
|
+
["itl", 4]
|
46
|
+
]
|
47
|
+
cattr_reader :definitions
|
48
|
+
|
49
|
+
@@all = nil
|
50
|
+
def self.all
|
51
|
+
@@all ||= definitions.collect do |text_code, numerical_code|
|
52
|
+
new(text_code, numerical_code)
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
end
|