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.
-
#queue ⇒ Object
readonly
Returns the value of attribute queue.
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.
148 149 150 151 152 153 154 |
# File 'lib/mormon/osm_router.rb', line 148 def initialize(loader, = {}) algorithm = .delete(:algorithm) || :astar algorithm_class = "Mormon::OSM::Algorithm::#{algorithm.to_s.capitalize}".constantize @loader = loader @algorithm = algorithm_class.new self, end |
Instance Attribute Details
#algorithm ⇒ Object (readonly)
Returns the value of attribute algorithm.
146 147 148 |
# File 'lib/mormon/osm_router.rb', line 146 def algorithm @algorithm end |
#loader ⇒ Object (readonly)
Returns the value of attribute loader.
146 147 148 |
# File 'lib/mormon/osm_router.rb', line 146 def loader @loader end |
#queue ⇒ Object (readonly)
Returns the value of attribute queue.
146 147 148 |
# File 'lib/mormon/osm_router.rb', line 146 def queue @queue end |
Instance Method Details
#find_route(node_start, node_end, transport) ⇒ Object
156 157 158 159 160 161 162 163 164 165 166 167 |
# File 'lib/mormon/osm_router.rb', line 156 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 |