app/models/chouette/route.rb in ninoxe-0.1.6 vs app/models/chouette/route.rb in ninoxe-1.0.0
- old
+ new
@@ -4,11 +4,11 @@
attr_accessor :wayback_code
attr_accessor :direction_code
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
+ attr_accessible :comment, :opposite_route_id, :published_name, :number, :direction, :wayback, :stop_points_attributes
def self.nullable_attributes
[:published_name, :comment, :number]
end
@@ -19,11 +19,11 @@
def timeless
all( :conditions => ['vehicle_journeys.id NOT IN (?)', Chouette::VehicleJourneyAtStop.where( :stop_point_id => proxy_association.owner.journey_patterns.pluck( :departure_stop_point_id)).pluck(:vehicle_journey_id)] )
end
end
belongs_to :opposite_route, :class_name => 'Chouette::Route', :foreign_key => :opposite_route_id
- has_many :stop_points, :order => 'position', :dependent => :destroy do
+ has_many :stop_points, inverse_of: :route, :order => 'position', :dependent => :destroy do
def find_by_stop_area(stop_area)
stop_area_ids = Integer === stop_area ? [stop_area] : (stop_area.children_in_depth + [stop_area]).map(&:id)
where( :stop_area_id => stop_area_ids).first or
raise ActiveRecord::RecordNotFound.new("Can't find a StopArea #{stop_area.inspect} in Route #{proxy_owner.id.inspect}'s StopPoints")
end
@@ -37,11 +37,11 @@
endpoint.position
when Integer
endpoint
else
raise ActiveRecord::RecordNotFound.new("Can't determine position in route #{proxy_owner.id} with #{departure.inspect}")
- end
+ end
end
where(" position between ? and ? ", between_positions.first, between_positions.last)
end
end
has_many :stop_areas, :through => :stop_points, :order => 'stop_points.position' do
@@ -50,18 +50,19 @@
String === endpoint ? Chouette::StopArea.find_by_objectid(endpoint) : endpoint
end
proxy_owner.stop_points.between(departure, arrival).includes(:stop_area).collect(&:stop_area)
end
end
+ accepts_nested_attributes_for :stop_points, :allow_destroy => :true
validates_presence_of :name
validates_presence_of :line
validates_presence_of :direction_code
validates_presence_of :wayback_code
-
+
before_destroy :dereference_opposite_route
-
+
def geometry_presenter
Chouette::Geometry::RoutePresenter.new self
end
def dereference_opposite_route
@@ -84,16 +85,16 @@
def sorted_vehicle_journeys
vehicle_journeys.includes( :vehicle_journey_at_stops, :journey_pattern).where( "vehicle_journey_at_stops.stop_point_id=journey_patterns.departure_stop_point_id").order( "vehicle_journey_at_stops.departure_time")
end
def self.direction_binding
- { "A" => "straight_forward",
+ { "A" => "straight_forward",
"R" => "backward",
"ClockWise" => "clock_wise",
"CounterClockWise" => "counter_clock_wise",
"North" => "north",
- "NorthWest" => "north_west",
+ "NorthWest" => "north_west",
"West" => "west",
"SouthWest" => "south_west",
"South" => "south",
"SouthEast" => "south_east",
"East" => "east",
@@ -103,11 +104,11 @@
return nil if self.class.direction_binding[direction].nil?
Chouette::Direction.new( self.class.direction_binding[direction])
end
def direction_code=(direction_code)
self.direction = nil
- self.class.direction_binding.each do |k,v|
+ self.class.direction_binding.each do |k,v|
self.direction = k if v==direction_code
end
end
@@directions = nil
def self.directions
@@ -120,25 +121,25 @@
return nil if self.class.wayback_binding[wayback].nil?
Chouette::Wayback.new( self.class.wayback_binding[wayback])
end
def wayback_code=(wayback_code)
self.wayback = nil
- self.class.wayback_binding.each do |k,v|
+ self.class.wayback_binding.each do |k,v|
self.wayback = k if v==wayback_code
end
end
@@waybacks = nil
def self.waybacks
@@waybacks ||= Chouette::Wayback.all
end
-
+
def stop_point_permutation?( stop_point_ids)
stop_points.map(&:id).map(&:to_s).sort == stop_point_ids.map(&:to_s).sort
end
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