Skip to content

Commit

Permalink
Changes the implicit dependencies an Adapter has
Browse files Browse the repository at this point in the history
Before, an adapter assumed that an object responds to #lat and #lng.
Now, an adapter assumes that an object responds to #[](key), where key
is :lat or :lng.
  • Loading branch information
t6d committed Aug 1, 2014
1 parent 01a1fe7 commit 9679f94
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 7 deletions.
9 changes: 8 additions & 1 deletion lib/routing/adapter/rest_adapter.rb
Expand Up @@ -52,7 +52,14 @@ def parse(response)
end

def convert_geo_points_to_params(geo_points)
Hash[geo_points.each_with_index.map { |point, i| [ "waypoint#{i}", "geo!#{point.fetch(:lat)},#{point.fetch(:lng)}" ] }]
Hash[geo_points.each_with_index.map do |point, i|
lat = point[:lat]
lng = point[:lng]

raise ArgumentError, "latitude or longitude missing" unless lat && lng

["waypoint#{i}", "geo!#{lat},#{lng}"]
end]
end
end
end
Expand Down
15 changes: 10 additions & 5 deletions lib/routing/adapter/test.rb
Expand Up @@ -7,11 +7,16 @@ class Test

def calculate(geo_points)
geo_points.collect do |point|
lat = point[:lat]
lng = point[:lng]

raise ArgumentError, "latitude or longitude missing" unless lat && lng

GeoPoint.new(
:lat => point.lat,
:lng => point.lng,
:original_lat => point.lat,
:original_lng => point.lng,
:lat => lat,
:lng => lng,
:original_lat => lat,
:original_lng => lng,
:relative_time => 100,
:distance => 100,
:waypoint => true
Expand All @@ -21,4 +26,4 @@ def calculate(geo_points)
end

end
end
end
9 changes: 8 additions & 1 deletion spec/routing/adapter/test_spec.rb
Expand Up @@ -8,7 +8,14 @@
end

describe '#calculate' do
let(:geo_points) { [double(lat: 1, lng: 2), double(lat: 3, lng: 4), double(lat: 5, lng: 6)] }
let(:geo_points) do
[
Routing::GeoPoint.new(lat: 1, lng: 2),
Routing::GeoPoint.new(lat: 3, lng: 4),
Routing::GeoPoint.new(lat: 5, lng: 6)
]
end


it 'returns an array of geopoints with values that are passed to the method' do
subject.calculate(geo_points).each_with_index do |new_geo_point, index|
Expand Down

0 comments on commit 9679f94

Please sign in to comment.