Class: ActiveRoad::Path
- Inherits:
-
Object
- Object
- ActiveRoad::Path
- Defined in:
- app/models/active_road/path.rb
Overview
A path is a link between differents objects :
- Departure
- Arrival
Instance Attribute Summary collapse
-
#arrival ⇒ Object
Returns the value of attribute arrival.
-
#departure ⇒ Object
Returns the value of attribute departure.
-
#physical_road ⇒ Object
(also: #road)
Returns the value of attribute physical_road.
Class Method Summary collapse
Instance Method Summary collapse
- #==(other) ⇒ Object (also: #eql?)
- #geometry_with_cache ⇒ Object (also: #geometry)
- #geometry_without_cache ⇒ Object
- #hash ⇒ Object
-
#initialize(attributes = {}) ⇒ Path
constructor
A new instance of Path.
- #length_in_meter ⇒ Object
- #length_on_road ⇒ Object
- #locations_on_road ⇒ Object
- #name ⇒ Object
- #paths ⇒ Object
- #reverse ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(attributes = {}) ⇒ Path
Returns a new instance of Path.
9 10 11 12 13 |
# File 'app/models/active_road/path.rb', line 9 def initialize(attributes = {}) attributes.each do |k, v| send("#{k}=", v) end end |
Instance Attribute Details
#arrival ⇒ Object
Returns the value of attribute arrival.
6 7 8 |
# File 'app/models/active_road/path.rb', line 6 def arrival @arrival end |
#departure ⇒ Object
Returns the value of attribute departure.
6 7 8 |
# File 'app/models/active_road/path.rb', line 6 def departure @departure end |
#physical_road ⇒ Object Also known as: road
Returns the value of attribute physical_road.
6 7 8 |
# File 'app/models/active_road/path.rb', line 6 def physical_road @physical_road end |
Class Method Details
.all(departure, arrivals, physical_road) ⇒ Object
40 41 42 43 44 |
# File 'app/models/active_road/path.rb', line 40 def self.all(departure, arrivals, physical_road) Array(arrivals).collect do |arrival| new :departure => departure, :arrival => arrival, :physical_road => physical_road end end |
Instance Method Details
#==(other) ⇒ Object Also known as: eql?
105 106 107 108 109 |
# File 'app/models/active_road/path.rb', line 105 def ==(other) [:departure, :arrival, :physical_road].all? do |attribute| other.respond_to?(attribute) and send(attribute) == other.send(attribute) end end |
#geometry_with_cache ⇒ Object Also known as: geometry
95 96 97 |
# File 'app/models/active_road/path.rb', line 95 def geometry_with_cache @geometry ||= geometry_without_cache end |
#geometry_without_cache ⇒ Object
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 |
# File 'app/models/active_road/path.rb', line 56 def geometry_without_cache # sorted_locations_on_road = locations_on_road.sort # reverse = (sorted_locations_on_road != locations_on_road) # geometry = road.line_substring(sorted_locations_on_road.first, sorted_locations_on_road.last) # geometry = geometry.reverse if reverse # geometry points = physical_road.geometry.points points_selected = [] if ActiveRoad::AccessPoint === departure || ActiveRoad::AccessPoint === arrival sorted_locations_on_road = locations_on_road.sort reverse = (sorted_locations_on_road != locations_on_road) if sorted_locations_on_road == [0, 1] if reverse return physical_road.geometry.reverse else return physical_road.geometry end end return road.line_substring(sorted_locations_on_road.first, sorted_locations_on_road.last) end departure_index = points.index(departure.geometry) arrival_index = points.index(arrival.geometry) if departure_index < arrival_index points_selected = points[arrival_index..departure_index] elsif arrival_index < departure_index points_selected = points.reverse![arrival_index..departure_index] else raise StandardError, "Junction is not on the physical road" end GeoRuby::SimpleFeatures::LineString.from_points(points) end |
#hash ⇒ Object
112 113 114 |
# File 'app/models/active_road/path.rb', line 112 def hash [departure, arrival, physical_road].hash end |
#length_in_meter ⇒ Object
31 32 33 |
# File 'app/models/active_road/path.rb', line 31 def length_in_meter length_on_road * road.length_in_meter end |
#length_on_road ⇒ Object
35 36 37 38 |
# File 'app/models/active_road/path.rb', line 35 def length_on_road begin_on_road, end_on_road = locations_on_road.sort end_on_road - begin_on_road end |
#locations_on_road ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 |
# File 'app/models/active_road/path.rb', line 19 def locations_on_road [departure, arrival].collect do |endpoint| location = if ActiveRoad::AccessPoint === endpoint road.locate_point endpoint.geometry else endpoint.location_on_road road end location = [0, [location, 1].min].max end end |
#name ⇒ Object
15 16 17 |
# File 'app/models/active_road/path.rb', line 15 def name "Path : #{departure} -> #{arrival}" end |
#paths ⇒ Object
48 49 50 |
# File 'app/models/active_road/path.rb', line 48 def paths arrival.paths - [reverse] end |
#reverse ⇒ Object
52 53 54 |
# File 'app/models/active_road/path.rb', line 52 def reverse self.class.new :departure => arrival, :arrival => departure, :physical_road => physical_road end |
#to_s ⇒ Object
101 102 103 |
# File 'app/models/active_road/path.rb', line 101 def to_s name end |