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/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

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::Here.

Returns:

  • (Object)

    Current default adapter.



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

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

Instance Attribute Details

#adapterObject (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.

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.



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

def calculate(*geo_points)
  calculate_with_stack(geo_points.flatten, middlewares + [@adapter])
end

#middlewaresArray<Routing::Middleware>

Returns a copy of the current middleware stack.

Returns:



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.

Parameters:

Returns:



66
67
68
# File 'lib/routing.rb', line 66

def use(middleware)
  @middlewares << middleware
end