Class: Chouette::Route
Constant Summary
collapse
- @@directions =
nil
- @@waybacks =
nil
Instance Attribute Summary collapse
Class Method Summary
collapse
-
.direction_binding ⇒ Object
-
.directions ⇒ Object
-
.nullable_attributes ⇒ Object
attr_accessible :direction_code, :wayback_code, :line_id, :objectid, :object_version, :creation_time, :creator_id, :name attr_accessible :comment, :opposite_route_id, :published_name, :number, :direction, :wayback, :stop_points_attributes.
-
.wayback_binding ⇒ Object
-
.waybacks ⇒ Object
Instance Method Summary
collapse
#build_objectid, #clean_object_id, #default_values, #fix_uniq_objectid, model_name, object_id_key, #objectid, #objectid_format_compliance, #prefix, #prepare_auto_columns, #reset_auto_columns, #timestamp_attributes_for_create, #timestamp_attributes_for_update, #uniq_objectid
#human_attribute_name, #nil_if_blank
Instance Attribute Details
#direction_code ⇒ Object
Returns the value of attribute direction_code.
6
7
8
|
# File 'app/models/chouette/route.rb', line 6
def direction_code
@direction_code
end
|
#wayback_code ⇒ Object
Returns the value of attribute wayback_code.
5
6
7
|
# File 'app/models/chouette/route.rb', line 5
def wayback_code
@wayback_code
end
|
Class Method Details
.direction_binding ⇒ Object
89
90
91
92
93
94
95
96
97
98
99
100
101
102
|
# File 'app/models/chouette/route.rb', line 89
def self.direction_binding
{ "A" => "straight_forward",
"R" => "backward",
"ClockWise" => "clock_wise",
"CounterClockWise" => "counter_clock_wise",
"North" => "north",
"NorthWest" => "north_west",
"West" => "west",
"SouthWest" => "south_west",
"South" => "south",
"SouthEast" => "south_east",
"East" => "east",
"NorthEast" => "north_east"}
end
|
.directions ⇒ Object
114
115
116
|
# File 'app/models/chouette/route.rb', line 114
def self.directions
@@directions ||= Chouette::Direction.all
end
|
.nullable_attributes ⇒ Object
attr_accessible :direction_code, :wayback_code, :line_id, :objectid, :object_version, :creation_time, :creator_id, :name attr_accessible :comment, :opposite_route_id, :published_name, :number, :direction, :wayback, :stop_points_attributes
11
12
13
|
# File 'app/models/chouette/route.rb', line 11
def self.nullable_attributes
[:published_name, :comment, :number, :name]
end
|
.wayback_binding ⇒ Object
117
118
119
|
# File 'app/models/chouette/route.rb', line 117
def self.wayback_binding
{ "A" => "straight_forward", "R" => "backward"}
end
|
.waybacks ⇒ Object
131
132
133
|
# File 'app/models/chouette/route.rb', line 131
def self.waybacks
@@waybacks ||= Chouette::Wayback.all
end
|
Instance Method Details
#dereference_opposite_route ⇒ Object
68
69
70
71
72
|
# File 'app/models/chouette/route.rb', line 68
def dereference_opposite_route
self.line.routes.each do |r|
r.update_attributes( :opposite_route => nil) if r.opposite_route == self
end
end
|
#geometry ⇒ Object
74
75
76
77
78
79
|
# File 'app/models/chouette/route.rb', line 74
def geometry
points = stop_areas.map(&:to_lat_lng).compact.map do |loc|
[loc.lng, loc.lat]
end
GeoRuby::SimpleFeatures::LineString.from_coordinates( points, 4326)
end
|
#geometry_presenter ⇒ Object
64
65
66
|
# File 'app/models/chouette/route.rb', line 64
def geometry_presenter
Chouette::Geometry::RoutePresenter.new self
end
|
#reorder!(stop_point_ids) ⇒ Object
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
|
# File 'app/models/chouette/route.rb', line 139
def reorder!( stop_point_ids)
return false unless stop_point_permutation?( stop_point_ids)
stop_area_id_by_stop_point_id = {}
stop_points.each do |sp|
stop_area_id_by_stop_point_id.merge!( sp.id => sp.stop_area_id)
end
reordered_stop_area_ids = []
stop_point_ids.each do |stop_point_id|
reordered_stop_area_ids << stop_area_id_by_stop_point_id[ stop_point_id.to_i]
end
stop_points.each_with_index do |sp, index|
if sp.stop_area_id.to_s != reordered_stop_area_ids[ index].to_s
sp.stop_area_id = reordered_stop_area_ids[ index]
result = sp.save!
end
end
return true
end
|
#sorted_vehicle_journeys ⇒ Object
85
86
87
|
# File 'app/models/chouette/route.rb', line 85
def sorted_vehicle_journeys
vehicle_journeys.joins(:journey_pattern, :vehicle_journey_at_stops).where("vehicle_journey_at_stops.stop_point_id=journey_patterns.departure_stop_point_id").order( "vehicle_journey_at_stops.departure_time")
end
|
#stop_point_permutation?(stop_point_ids) ⇒ Boolean
135
136
137
|
# File 'app/models/chouette/route.rb', line 135
def stop_point_permutation?( stop_point_ids)
stop_points.map(&:id).map(&:to_s).sort == stop_point_ids.map(&:to_s).sort
end
|
#time_tables ⇒ Object
81
82
83
|
# File 'app/models/chouette/route.rb', line 81
def time_tables
self.vehicle_journeys.joins(:time_tables).map(&:"time_tables").flatten.uniq
end
|