Class: Routing
- Inherits:
-
Object
- Object
- Routing
- Defined in:
- lib/routing.rb,
lib/routing/parser.rb,
lib/routing/adapter.rb,
lib/routing/version.rb,
lib/routing/geo_point.rb,
lib/routing/middleware.rb,
lib/routing/adapter/here.rb,
lib/routing/adapter/test.rb,
lib/routing/adapter/navteq.rb,
lib/routing/parser/here_simple.rb,
lib/routing/adapter/rest_adapter.rb,
lib/routing/parser/navteq_simple.rb
Overview
The Routing class is the main entry point for the library.
Defined Under Namespace
Modules: Adapter, Parser Classes: GeoPoint, Middleware
Constant Summary collapse
- VERSION =
"0.2.2"
Class Attribute Summary collapse
-
.default_adapter ⇒ Object
The default adapter/routing service that is used, if no one is specified.
Instance Attribute Summary collapse
-
#adapter ⇒ Object
readonly
Returns the value of attribute adapter.
Instance Method Summary collapse
-
#calculate(*geo_points) ⇒ Array<GeoPoint>
Calculates a route for the passed GeoPoints.
-
#initialize(adapter = self.class.default_adapter) {|_self| ... } ⇒ Routing
constructor
Creates a new instance of the routing class.
-
#middlewares ⇒ Array<Routing::Middleware>
Returns a copy of the current middleware stack.
-
#use(middleware) ⇒ Array<Routing::Middleware>
Adds an object to the middleware stack.
Constructor Details
#initialize(adapter = self.class.default_adapter) {|_self| ... } ⇒ Routing
Creates a new instance of the routing class
33 34 35 36 37 38 |
# File 'lib/routing.rb', line 33 def initialize(adapter = self.class.default_adapter) @adapter = adapter @middlewares = [] yield(self) if block_given? end |
Class Attribute Details
.default_adapter ⇒ Object
The default adapter/routing service that is used, if no one is specified. Currently this is Routing::Adapter::Here.
22 23 24 |
# File 'lib/routing.rb', line 22 def default_adapter @default_adapter ||= Routing::Adapter::Here.new end |
Instance Attribute Details
#adapter ⇒ Object (readonly)
Returns the value of attribute adapter.
28 29 30 |
# File 'lib/routing.rb', line 28 def adapter @adapter end |
Instance Method Details
#calculate(*geo_points) ⇒ Array<GeoPoint>
Calculates a route for the passed GeoPoints. These will be passed through the middleware stack and will finally be given to the configured adapter which calculates a route out of it.
57 58 59 |
# File 'lib/routing.rb', line 57 def calculate(*geo_points) calculate_with_stack(geo_points.flatten, middlewares + [@adapter]) end |
#middlewares ⇒ Array<Routing::Middleware>
Returns a copy of the current middleware stack.
44 45 46 |
# File 'lib/routing.rb', line 44 def middlewares @middlewares.dup end |
#use(middleware) ⇒ Array<Routing::Middleware>
Adds an object to the middleware stack.
66 67 68 |
# File 'lib/routing.rb', line 66 def use(middleware) @middlewares << middleware end |