Class: Routing

Inherits:
Object
  • Object
show all
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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(adapter = self.class.default_adapter) {|_self| ... } ⇒ Routing

Creates a new instance of the routing class

Parameters:

  • adapter (Object) (defaults to: self.class.default_adapter)

    Adapter for the routing service that should be used, defaults to Routing::Adapter::Navteq.

Yields:

  • (_self)

Yield Parameters:

  • _self (Routing)

    the object that the method was called on



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_adapterObject

The default adapter/routing service that is used, if no one is specified. Currently this is Routing::Adapter::Navteq.

Returns:

  • (Object)

    Current default adapter.



22
23
24
# File 'lib/routing.rb', line 22

def default_adapter
  @default_adapter ||= Routing::Adapter::Navteq.new
end

Instance Attribute Details

#middlewaresObject

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.

Parameters:

  • geo_points (Array<GeoPoint>)

    An array of geo points to calculate a route of.

Returns:

  • (Array<GeoPoint>)

    An array of geo points that represent the calculated route.



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.

Parameters:

Returns:



58
59
60
# File 'lib/routing.rb', line 58

def use(middleware)
  @middlewares << middleware
end