Sha256: 2f31c2fca1b28ea312618c6b03c0759653a71b2bcbd26147667c4b4c299ec5d0

Contents?: true

Size: 1.03 KB

Versions: 1

Compression:

Stored size: 1.03 KB

Contents

class ActiveRoad::AccessLink

  attr_accessor :departure, :arrival

  def initialize(attributes = {})
    attributes.each do |k, v|
      send("#{k}=", v)
    end
  end

  def name
    "AccessLink : #{departure} -> #{arrival}"
  end

  alias_method :to_s, :name

  def self.from(location)
    ActiveRoad::AccessPoint.from(location).collect do |access_point|
      new :departure => location, :arrival => access_point
    end
  end

  def length
    @length ||= departure.to_geometry.spherical_distance arrival.to_geometry
  end
  # TODO Delete this hack due to postgis adapter in physical road
  alias_method :length_in_meter, :length 

  def geometry
    @geometry ||= GeoRuby::SimpleFeatures::LineString.from_points [departure.to_geometry, arrival.to_geometry]
  end
  alias_method :to_geometry, :geometry

  delegate :access_to_road?, :to => :arrival

  def paths
    arrival.respond_to?(:paths) ? arrival.paths : [arrival]
  end

  def access_to_road?(road)
    arrival.respond_to?(:access_to_road?) ? arrival.access_to_road?(road) : false
  end

end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
active_road-0.0.3 app/models/active_road/access_link.rb