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/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.0.4"
Class Attribute Summary collapse
-
.default_adapter ⇒ Object
The default adapter/routing service that is used, if no one is specified.
Instance Attribute Summary collapse
-
#middlewares ⇒ Object
Returns the value of attribute middlewares.
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.
-
#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::Navteq.
22 23 24 |
# File 'lib/routing.rb', line 22 def default_adapter @default_adapter ||= Routing::Adapter::Navteq.new end |
Instance Attribute Details
#middlewares ⇒ Object
Returns the value of attribute middlewares.
28 29 30 |
# File 'lib/routing.rb', line 28 def middlewares @middlewares 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.
49 50 51 |
# File 'lib/routing.rb', line 49 def calculate(*geo_points) calculate_with_stack(geo_points.flatten, middlewares + [@adapter]) end |
#use(middleware) ⇒ Array<Routing::Middleware>
Adds an object to the middleware stack.
58 59 60 |
# File 'lib/routing.rb', line 58 def use(middleware) @middlewares << middleware end |