Skip to content

Commit

Permalink
Adds polylines gem. Adds polylines and polylines_as_points methods
Browse files Browse the repository at this point in the history
  • Loading branch information
Chris Vannoy committed Aug 16, 2016
1 parent c4be285 commit 56a8981
Show file tree
Hide file tree
Showing 3 changed files with 15 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

0 comments on commit 56a8981

Please sign in to comment.