Class: TollBooth::Location

Inherits:
Object
  • Object
show all
Defined in:
lib/toll_booth/location.rb

Overview

Represents a location that you would want directions from or to A location has the following attributes:

  • description

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(description) ⇒ Location

create a new location

Parameters:

  • description (String)

    address or zipcode of the location



10
11
12
# File 'lib/toll_booth/location.rb', line 10

def initialize(description)
  @description = description
end

Instance Attribute Details

#descriptionObject

Returns the value of attribute description.



6
7
8
# File 'lib/toll_booth/location.rb', line 6

def description
  @description
end

Instance Method Details

#drive_to(destinations) ⇒ TollBooth::RouteCollection

get driving routes to the destinations specified

Examples:

@origin = TollBooth::Location.new("4 Yawkey Way, Boston, MA")
@destination = TollBooth::Location.new("1 Fleetcenter Place, Boston, MA")
@routes = @origin.drive_to(@destination)
if @routes.found?
  @routes[0].distance              #distance in miles
  @routes[0].drive_time            #drive time in seconds
  @routes[0].name                  #name of route (usually specified when multiple routes are returned)
  @routes[0].steps                 #array of TollBooth::Steps to take
  @routes[0].steps[0].distance     #distance of step in miles
  @routes[0].steps[0].description  #summary of step
else
  puts @routes.errors.join(",")
end

Parameters:

  • destinations (TollBooth::Location, Array)

    a single location or list of locations to drive to

Returns:



31
32
33
34
35
# File 'lib/toll_booth/location.rb', line 31

def drive_to(destinations)
  destinations = [destinations] if !destinations.is_a?(Array)

  TollBooth::Route.find(self, destinations)
end