Skip to content

Commit

Permalink
Merge branch 'fix_existing_tests' into polylines_support
Browse files Browse the repository at this point in the history
  • Loading branch information
Chris Vannoy committed Aug 16, 2016
2 parents c29df19 + 496f2cd commit fba1be6
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 0 deletions.
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
source :rubygems

gem 'nokogiri'
gem 'polylines'
5 changes: 5 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,14 @@ GEM
mini_portile (0.5.0)
nokogiri (1.6.0)
mini_portile (~> 0.5.0)
polylines (0.3.0)

PLATFORMS
ruby

DEPENDENCIES
nokogiri
polylines

BUNDLED WITH
1.12.5
9 changes: 9 additions & 0 deletions lib/google_directions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
require 'net/http'
require 'open-uri'
require 'nokogiri'
require 'polylines'

class GoogleDirections

Expand Down Expand Up @@ -87,6 +88,14 @@ def steps
end
end

def polylines
@doc.css('polyline').map{|poly| poly.text.strip}
end

def polylines_as_points
polylines.map{|poly| Polylines::Decoder.decode_polyline(poly)}.flatten(1).uniq
end

private

def convert_to_minutes(text)
Expand Down
11 changes: 11 additions & 0 deletions test/unit/google_directions_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -54,4 +54,15 @@ def test_zero_distance_text
directions = GoogleDirections.new("27 Beemdenlaan, 2550 Kontich", "499 Gordonsville Highway, 38563")
assert_equal "0 km", directions.distance_text
end

def test_polylines_length
directions = GoogleDirections.new("Place du Maquis du Vercors PARIS-19EME", "rue poissoniere 75002 paris")
assert_equal 15, directions.polylines.length
end

def test_polylines_as_points_length
directions = GoogleDirections.new("Place du Maquis du Vercors PARIS-19EME", "rue poissoniere 75002 paris")
assert_equal 279, directions.polylines_as_points.length
end

end

0 comments on commit fba1be6

Please sign in to comment.