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(tags = {}) ⇒ 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?
74 75 76 77 78 |
# File 'app/models/active_road/path.rb', line 74 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
64 65 66 |
# File 'app/models/active_road/path.rb', line 64 def geometry_with_cache @geometry ||= geometry_without_cache end |
#geometry_without_cache ⇒ Object
56 57 58 59 60 61 62 |
# 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 geometry = geometry.reverse if reverse geometry end |
#hash ⇒ Object
81 82 83 |
# File 'app/models/active_road/path.rb', line 81 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 GeoRuby::SimpleFeatures::Point === endpoint road.locate_point endpoint 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(tags = {}) ⇒ 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
70 71 72 |
# File 'app/models/active_road/path.rb', line 70 def to_s name end |