Sha256: 96dc36a1db905c34fb295f31ba19cfac6ed720431c61aeb5d56b521ed740d43b
Contents?: true
Size: 1.48 KB
Versions: 1
Compression:
Stored size: 1.48 KB
Contents
# A junction is a connection between 1 to n physical roads require "activerecord-postgres-hstore" module ActiveRoad class Junction < ActiveRoad::Base serialize :tags, ActiveRecord::Coders::Hstore attr_accessible :objectid, :tags, :geometry, :height, :waiting_constraint validates_uniqueness_of :objectid has_and_belongs_to_many :physical_roads, :class_name => "ActiveRoad::PhysicalRoad",:uniq => true has_many :junction_conditionnal_costs, :class_name => "ActiveRoad::JunctionConditionnalCost" %w[max_speed, max_slope].each do |key| attr_accessible key scope "has_#{key}", lambda { |value| where("properties @> hstore(?, ?)", key, value) } define_method(key) do properties && properties[key] end define_method("#{key}=") do |value| self.properties = (properties || {}).merge(key => value) end end def location_on_road(road) (@location_on_road ||= {})[road.id] ||= road.locate_point(geometry) end def paths(tags = {}) ActiveRoad::PhysicalRoadFilter.new(tags, physical_roads).filter.includes(:junctions).collect do |physical_road| ActiveRoad::Path.all self, (physical_road.junctions - [self]), physical_road end.flatten end def access_to_road?(road) physical_roads.include? road end def to_geometry geometry end def to_s "Junction @#{geometry.to_lat_lng}" end def name physical_roads.join(" - ") end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
active_road-0.0.2 | app/models/active_road/junction.rb |