Class: TollBooth::Route
- Inherits:
-
Object
- Object
- TollBooth::Route
- Includes:
- HTTParty
- Defined in:
- lib/toll_booth/route.rb
Instance Attribute Summary collapse
-
#distance ⇒ Object
Returns the value of attribute distance.
-
#name ⇒ Object
Returns the value of attribute name.
-
#steps ⇒ Object
Returns the value of attribute steps.
-
#travel_time ⇒ Object
Returns the value of attribute travel_time.
Class Method Summary collapse
-
.find(origin, destinations) ⇒ TollBooth::RouteCollection
get driving directions from the origin to the specified destination(s).
-
.parse(response) ⇒ TollBooth::RouteCollection
parses response from google.
Instance Attribute Details
#distance ⇒ Object
Returns the value of attribute distance.
4 5 6 |
# File 'lib/toll_booth/route.rb', line 4 def distance @distance end |
#name ⇒ Object
Returns the value of attribute name.
4 5 6 |
# File 'lib/toll_booth/route.rb', line 4 def name @name end |
#steps ⇒ Object
Returns the value of attribute steps.
4 5 6 |
# File 'lib/toll_booth/route.rb', line 4 def steps @steps end |
#travel_time ⇒ Object
Returns the value of attribute travel_time.
4 5 6 |
# File 'lib/toll_booth/route.rb', line 4 def travel_time @travel_time end |
Class Method Details
.find(origin, destinations) ⇒ TollBooth::RouteCollection
get driving directions from the origin to the specified destination(s)
16 17 18 19 20 21 22 23 |
# File 'lib/toll_booth/route.rb', line 16 def find(origin, destinations) response = get("", :query => {:q => "from: #{origin.description} " + destinations.collect{|d| " to: #{d.description}"}.join("")}) routes = parse(response) routes end |
.parse(response) ⇒ TollBooth::RouteCollection
parses response from google
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/toll_booth/route.rb', line 28 def parse(response) resp = JSON.parse(response.body) code = response["Status"]["code"] routes = TollBooth::RouteCollection.new if code == 200 resp["Directions"]["Routes"].each do |r| route = new route.distance = r["Distance"]["html"].gsub(" mi", "").to_f route.travel_time = ChronicDuration.parse(r["Duration"]["html"]) route.steps = TollBooth::RouteStep.parse(r["Steps"]) routes << route end else routes.errors = [error_for(code)] end routes end |