Class: MapQuestDirections
- Inherits:
-
Object
- Object
- MapQuestDirections
- Defined in:
- lib/mapquest_directions.rb
Instance Method Summary collapse
- #distance_in_miles ⇒ Object
- #drive_time_in_minutes ⇒ Object
- #find_status ⇒ Object
-
#initialize(location_1, location_2) ⇒ MapQuestDirections
constructor
A new instance of MapQuestDirections.
- #status ⇒ Object
- #xml ⇒ Object
- #xml_call ⇒ Object
Constructor Details
#initialize(location_1, location_2) ⇒ MapQuestDirections
Returns a new instance of MapQuestDirections.
6 7 8 9 10 11 12 13 |
# File 'lib/mapquest_directions.rb', line 6 def initialize(location_1, location_2) @base_url = "http://www.mapquestapi.com/directions/v1/route?key=#{MAPQUEST_KEY}&outFormat=xml&" @location_1 = location_1 @location_2 = location_2 = "from=#{transcribe(@location_1)}&to=#{transcribe(@location_2)}" @xml_call = @base_url + @status = find_status end |
Instance Method Details
#distance_in_miles ⇒ Object
42 43 44 45 46 47 48 49 |
# File 'lib/mapquest_directions.rb', line 42 def distance_in_miles if @status != "0" distance_in_miles = 0 else doc = Nokogiri::XML(xml) distance_in_miles = doc.css("distance").first.text.to_i end end |
#drive_time_in_minutes ⇒ Object
32 33 34 35 36 37 38 39 40 |
# File 'lib/mapquest_directions.rb', line 32 def drive_time_in_minutes if @status != "0" drive_time = 0 else doc = Nokogiri::XML(xml) drive_time = doc.css("time").first.text convert_to_minutes(drive_time) end end |
#find_status ⇒ Object
15 16 17 18 |
# File 'lib/mapquest_directions.rb', line 15 def find_status doc = Nokogiri::XML(xml) doc.css("statusCode").text end |
#status ⇒ Object
51 52 53 |
# File 'lib/mapquest_directions.rb', line 51 def status @status end |
#xml ⇒ Object
20 21 22 23 24 25 26 |
# File 'lib/mapquest_directions.rb', line 20 def xml unless @xml.nil? @xml else @xml ||= get_url(@xml_call) end end |
#xml_call ⇒ Object
28 29 30 |
# File 'lib/mapquest_directions.rb', line 28 def xml_call @xml_call end |