aboutsummaryrefslogtreecommitdiffstats
path: root/app/models/chouette/connection_link.rb
blob: fb93e5f90a8f86c2607c2c87ccbfc9388b1a1aed (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
module Chouette
  class ConnectionLink < Chouette::TridentActiveRecord
    has_metadata
    include ObjectidSupport
    include ConnectionLinkRestrictions

    attr_accessor :connection_link_type

    belongs_to :departure, :class_name => 'Chouette::StopArea'
    belongs_to :arrival, :class_name => 'Chouette::StopArea'

    validates_presence_of :name

    def self.nullable_attributes
      [:link_distance, :default_duration, :frequent_traveller_duration, :occasional_traveller_duration,
        :mobility_restricted_traveller_duration, :link_type]
    end

    def connection_link_type
      link_type && Chouette::ConnectionLinkType.new( link_type.underscore)
    end

    def connection_link_type=(connection_link_type)
      self.link_type = (connection_link_type ? connection_link_type.camelcase : nil)
    end

    @@connection_link_types = nil
    def self.connection_link_types
      @@connection_link_types ||= Chouette::ConnectionLinkType.all
    end

    def possible_areas
      Chouette::StopArea.where("area_type != 'ITL'")
    end

    def stop_areas
      Chouette::StopArea.where(:id => [self.departure_id,self.arrival_id])
    end

    def geometry
      GeoRuby::SimpleFeatures::LineString.from_points( [ departure.geometry, arrival.geometry], 4326) if departure.geometry and arrival.geometry
    end

    def geometry_presenter
      Chouette::Geometry::ConnectionLinkPresenter.new self
    end

  end
end