Class: Mormon::OSM::Router
- Inherits:
-
Object
- Object
- Mormon::OSM::Router
- Defined in:
- lib/mormon/osm_router.rb
Instance Attribute Summary collapse
-
#algorithm ⇒ Object
readonly
Returns the value of attribute algorithm.
-
#loader ⇒ Object
readonly
Returns the value of attribute loader.
Instance Method Summary collapse
- #find_route(node_start, node_end, transport) ⇒ Object
-
#initialize(loader, options = {}) ⇒ Router
constructor
A new instance of Router.
Constructor Details
#initialize(loader, options = {}) ⇒ Router
Returns a new instance of Router.
147 148 149 150 151 152 153 154 155 |
# File 'lib/mormon/osm_router.rb', line 147 def initialize(loader, = {}) @loader = loader @options = algorithm = @options.delete(:algorithm) || :astar algorithm_classname = algorithm.to_s.capitalize algorithm_class = "Mormon::OSM::Algorithm::#{algorithm_classname}".constantize @algorithm = algorithm_class.new(self, @options) end |
Instance Attribute Details
#algorithm ⇒ Object (readonly)
Returns the value of attribute algorithm.
145 146 147 |
# File 'lib/mormon/osm_router.rb', line 145 def algorithm @algorithm end |
#loader ⇒ Object (readonly)
Returns the value of attribute loader.
145 146 147 |
# File 'lib/mormon/osm_router.rb', line 145 def loader @loader end |
Instance Method Details
#find_route(node_start, node_end, transport) ⇒ Object
157 158 159 160 161 162 163 164 165 166 167 168 |
# File 'lib/mormon/osm_router.rb', line 157 def find_route(node_start, node_end, transport) result, nodes = algorithm.route(node_start.to_i, node_end.to_i, transport.to_sym) return [result,[]] if result != 'success' nodes.map! do |node| data = loader.nodes[node.to_s] [data[:lat], data[:lon]] end [result, nodes] end |