Class: Chouette::JourneyPattern

Inherits:
TridentActiveRecord show all
Defined in:
app/models/chouette/journey_pattern.rb

Instance Method Summary collapse

Methods inherited from TridentActiveRecord

#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

Methods inherited from ActiveRecord

#human_attribute_name, #nil_if_blank, nullable_attributes

Instance Method Details

#arrival_stop_pointObject



28
29
30
31
# File 'app/models/chouette/journey_pattern.rb', line 28

def arrival_stop_point
  return unless arrival_stop_point_id
  Chouette::StopPoint.find( arrival_stop_point_id)
end

#departure_stop_pointObject



23
24
25
26
# File 'app/models/chouette/journey_pattern.rb', line 23

def departure_stop_point
  return unless departure_stop_point_id
  Chouette::StopPoint.find( departure_stop_point_id)
end

#shortcuts_update_for_add(stop_point) ⇒ Object



33
34
35
36
37
38
39
40
41
# File 'app/models/chouette/journey_pattern.rb', line 33

def shortcuts_update_for_add( stop_point)
  stop_points << stop_point unless stop_points.include?( stop_point)

  ordered_stop_points = stop_points
  ordered_stop_points = ordered_stop_points.sort { |a,b| a.position <=> b.position} unless ordered_stop_points.empty?

  self.update_attributes( :departure_stop_point_id => (ordered_stop_points.first && ordered_stop_points.first.id),
                           :arrival_stop_point_id => (ordered_stop_points.last && ordered_stop_points.last.id))
end

#shortcuts_update_for_remove(stop_point) ⇒ Object



43
44
45
46
47
48
49
50
51
# File 'app/models/chouette/journey_pattern.rb', line 43

def shortcuts_update_for_remove( stop_point)
  stop_points.delete( stop_point) if stop_points.include?( stop_point)
  
  ordered_stop_points = stop_points
  ordered_stop_points = ordered_stop_points.sort { |a,b| a.position <=> b.position} unless ordered_stop_points.empty?

  self.update_attributes( :departure_stop_point_id => (ordered_stop_points.first && ordered_stop_points.first.id),
                           :arrival_stop_point_id => (ordered_stop_points.last && ordered_stop_points.last.id))
end

#special_updateObject

TODO: this a workarround otherwise, we loose the first stop_point when creating a new journey_pattern



17
18
19
20
21
# File 'app/models/chouette/journey_pattern.rb', line 17

def special_update
  bck_sp = self.stop_points.map {|s| s}
  self.update_attributes :stop_points => []
  self.update_attributes :stop_points => bck_sp
end

#vjas_add(stop_point) ⇒ Object



53
54
55
56
57
58
59
# File 'app/models/chouette/journey_pattern.rb', line 53

def vjas_add( stop_point)
  return if new_record? 

  vehicle_journeys.each do |vj|
    vjas = vj.vehicle_journey_at_stops.create :stop_point_id => stop_point.id 
  end
end

#vjas_remove(stop_point) ⇒ Object



61
62
63
64
65
66
67
# File 'app/models/chouette/journey_pattern.rb', line 61

def vjas_remove( stop_point)
  return if new_record?
  
  vehicle_journey_at_stops.where( :stop_point_id => stop_point.id).each do |vjas|
    vjas.destroy
  end
end