parallel588_nominatim 0.0.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +21 -0
- data/.rspec +2 -0
- data/.travis.yml +7 -0
- data/CHANGELOG.md +15 -0
- data/Gemfile +8 -0
- data/Guardfile +13 -0
- data/LICENSE +22 -0
- data/README.md +90 -0
- data/Rakefile +11 -0
- data/lib/nominatim/address.rb +83 -0
- data/lib/nominatim/client.rb +41 -0
- data/lib/nominatim/configuration.rb +49 -0
- data/lib/nominatim/place.rb +93 -0
- data/lib/nominatim/point.rb +30 -0
- data/lib/nominatim/polygon.rb +13 -0
- data/lib/nominatim/response/parse_json.rb +16 -0
- data/lib/nominatim/reverse.rb +44 -0
- data/lib/nominatim/search.rb +99 -0
- data/lib/nominatim/version.rb +3 -0
- data/lib/nominatim.rb +36 -0
- data/nominatim.gemspec +26 -0
- data/spec/fixtures/reverse.json +1 -0
- data/spec/fixtures/search.json +1 -0
- data/spec/nominatim/address_spec.rb +209 -0
- data/spec/nominatim/client_spec.rb +23 -0
- data/spec/nominatim/place_spec.rb +172 -0
- data/spec/nominatim/point_spec.rb +53 -0
- data/spec/nominatim/polygon_spec.rb +19 -0
- data/spec/nominatim/reverse_spec.rb +68 -0
- data/spec/nominatim/search_spec.rb +140 -0
- data/spec/nominatim_spec.rb +66 -0
- data/spec/spec_helper.rb +38 -0
- metadata +185 -0
@@ -0,0 +1,23 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Nominatim::Client do
|
4
|
+
after do
|
5
|
+
WebMock.reset!
|
6
|
+
end
|
7
|
+
|
8
|
+
describe '#get' do
|
9
|
+
before do
|
10
|
+
stub_get('/search').to_return(body: "[]")
|
11
|
+
end
|
12
|
+
|
13
|
+
it 'requests the correct resource' do
|
14
|
+
Nominatim::Client.new.get('/search')
|
15
|
+
a_get('/search').should have_been_requested
|
16
|
+
end
|
17
|
+
|
18
|
+
it 'parses the body' do
|
19
|
+
response = Nominatim::Client.new.get('/search')
|
20
|
+
response.body.should eq []
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,172 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Nominatim::Place do
|
4
|
+
describe '#display_name' do
|
5
|
+
it 'returns a full name when set with display_name' do
|
6
|
+
place = Nominatim::Place.new(display_name: 'Los Angeles, California, United States of America')
|
7
|
+
place.display_name.should eq 'Los Angeles, California, United States of America'
|
8
|
+
end
|
9
|
+
|
10
|
+
it 'returns nil when not set' do
|
11
|
+
place = Nominatim::Place.new
|
12
|
+
place.display_name.should be_nil
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
describe '#class' do
|
17
|
+
it 'returns a class when set with class' do
|
18
|
+
place = Nominatim::Place.new(class: 'place')
|
19
|
+
place.class.should eq 'place'
|
20
|
+
end
|
21
|
+
|
22
|
+
it 'returns nil when not set' do
|
23
|
+
place = Nominatim::Place.new
|
24
|
+
place.class.should be_nil
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
describe '#type' do
|
29
|
+
it 'returns a type when set with type' do
|
30
|
+
place = Nominatim::Place.new(type: 'county')
|
31
|
+
place.type.should eq 'county'
|
32
|
+
end
|
33
|
+
|
34
|
+
it 'returns nil when not set' do
|
35
|
+
place = Nominatim::Place.new
|
36
|
+
place.type.should be_nil
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
describe '#address' do
|
41
|
+
it 'returns a Nominatim::Address when set' do
|
42
|
+
place = Nominatim::Place.new(address: {county: 'Los Angeles', state: 'California', country: 'United States of America'})
|
43
|
+
place.address.should be_a Nominatim::Address
|
44
|
+
end
|
45
|
+
|
46
|
+
it 'returns nil when not set' do
|
47
|
+
place = Nominatim::Place.new
|
48
|
+
place.address.should be_nil
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
describe '#lat' do
|
53
|
+
it 'returns a latitude when set with lat' do
|
54
|
+
place = Nominatim::Place.new(lat: '52.5487969264788', lon: '-1.81642935385411')
|
55
|
+
place.lat.should eq 52.5487969264788
|
56
|
+
end
|
57
|
+
|
58
|
+
it 'returns nil when not set' do
|
59
|
+
place = Nominatim::Place.new
|
60
|
+
place.lat.should be_nil
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
describe '#latitude' do
|
65
|
+
it 'returns a latitude when set with lat' do
|
66
|
+
place = Nominatim::Place.new(lat: '52.5487969264788', lon: '-1.81642935385411')
|
67
|
+
place.latitude.should eq 52.5487969264788
|
68
|
+
end
|
69
|
+
|
70
|
+
it 'returns nil when not set' do
|
71
|
+
place = Nominatim::Place.new
|
72
|
+
place.latitude.should be_nil
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
describe '#lon' do
|
77
|
+
it 'returns a longitude when set with lon' do
|
78
|
+
place = Nominatim::Place.new(lat: '52.5487969264788', lon: '-1.81642935385411')
|
79
|
+
place.lon.should eq -1.81642935385411
|
80
|
+
end
|
81
|
+
|
82
|
+
it 'returns nil when not set' do
|
83
|
+
place = Nominatim::Place.new
|
84
|
+
place.lon.should be_nil
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
describe '#longitude' do
|
89
|
+
it 'returns a longitude when set with lon' do
|
90
|
+
place = Nominatim::Place.new(lat: '52.5487969264788', lon: '-1.81642935385411')
|
91
|
+
place.longitude.should eq -1.81642935385411
|
92
|
+
end
|
93
|
+
|
94
|
+
it 'returns nil when not set' do
|
95
|
+
place = Nominatim::Place.new
|
96
|
+
place.longitude.should be_nil
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
describe '#boundingbox' do
|
101
|
+
it 'returns a boundingbox when set with boundingbox' do
|
102
|
+
place = Nominatim::Place.new(boundingbox: ["52.5487442016602", "52.5488510131836", "-1.81651306152344", "-1.81634628772736"])
|
103
|
+
place.boundingbox.should eq ["52.5487442016602", "52.5488510131836", "-1.81651306152344", "-1.81634628772736"]
|
104
|
+
end
|
105
|
+
|
106
|
+
it 'returns nil when not set' do
|
107
|
+
place = Nominatim::Place.new
|
108
|
+
place.boundingbox.should be_nil
|
109
|
+
end
|
110
|
+
end
|
111
|
+
|
112
|
+
describe '#bounding_box' do
|
113
|
+
it 'returns a bounding box when set with boundingbox' do
|
114
|
+
place = Nominatim::Place.new(boundingbox: ["52.5487442016602", "52.5488510131836", "-1.81651306152344", "-1.81634628772736"])
|
115
|
+
place.bounding_box.should eq ["52.5487442016602", "52.5488510131836", "-1.81651306152344", "-1.81634628772736"]
|
116
|
+
end
|
117
|
+
|
118
|
+
it 'returns nil when not set' do
|
119
|
+
place = Nominatim::Place.new
|
120
|
+
place.bounding_box.should be_nil
|
121
|
+
end
|
122
|
+
end
|
123
|
+
|
124
|
+
describe '#polygonpoints' do
|
125
|
+
it 'returns polygon points when set with polygonpoints' do
|
126
|
+
place = Nominatim::Place.new(polygonpoints: [["-1.816513", "52.5487566"], ["-1.8164913", "52.548824"], ["-1.8164685", "52.5488213"]])
|
127
|
+
place.polygonpoints.should be_a Nominatim::Polygon
|
128
|
+
end
|
129
|
+
|
130
|
+
it 'returns nil when not set' do
|
131
|
+
place = Nominatim::Place.new
|
132
|
+
place.polygonpoints.should be_nil
|
133
|
+
end
|
134
|
+
end
|
135
|
+
|
136
|
+
describe '#place_id' do
|
137
|
+
it 'returns a place id when set with place_id' do
|
138
|
+
place = Nominatim::Place.new(place_id: '84327444')
|
139
|
+
place.place_id.should eq 84327444
|
140
|
+
end
|
141
|
+
|
142
|
+
it 'returns nil when not set' do
|
143
|
+
place = Nominatim::Place.new
|
144
|
+
place.place_id.should be_nil
|
145
|
+
end
|
146
|
+
end
|
147
|
+
|
148
|
+
describe '#osm_id' do
|
149
|
+
it 'returns an osm id when set with osm_id' do
|
150
|
+
place = Nominatim::Place.new(osm_id: '90394480')
|
151
|
+
place.osm_id.should eq 90394480
|
152
|
+
end
|
153
|
+
|
154
|
+
it 'returns nil when not set' do
|
155
|
+
place = Nominatim::Place.new
|
156
|
+
place.osm_id.should be_nil
|
157
|
+
end
|
158
|
+
end
|
159
|
+
|
160
|
+
describe '#osm_type' do
|
161
|
+
it 'returns an osm type when set with osm_type' do
|
162
|
+
place = Nominatim::Place.new(osm_type: 'way')
|
163
|
+
place.osm_type.should eq 'way'
|
164
|
+
end
|
165
|
+
|
166
|
+
it 'returns nil when not set' do
|
167
|
+
place = Nominatim::Place.new
|
168
|
+
place.osm_type.should be_nil
|
169
|
+
end
|
170
|
+
end
|
171
|
+
|
172
|
+
end
|
@@ -0,0 +1,53 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Nominatim::Point do
|
4
|
+
let(:point) { Nominatim::Point.new(52.5487969264788, -1.81642935385411) }
|
5
|
+
|
6
|
+
describe '#lat' do
|
7
|
+
it 'returns the latitude' do
|
8
|
+
point.lat.should eq 52.5487969264788
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
describe '#latitude' do
|
13
|
+
it 'returns the latitude' do
|
14
|
+
point.latitude.should eq 52.5487969264788
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
describe '#lon' do
|
19
|
+
it 'returns the longitude' do
|
20
|
+
point.lon.should eq -1.81642935385411
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
describe '#longitude' do
|
25
|
+
it 'returns the longitude' do
|
26
|
+
point.longitude.should eq -1.81642935385411
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
describe '#to_a' do
|
31
|
+
it 'returns an array representing the point' do
|
32
|
+
point.to_a.should eq [52.5487969264788, -1.81642935385411]
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
describe '#to_s' do
|
37
|
+
it 'returns a string representing the point' do
|
38
|
+
point.to_s.should eq '[52.5487969264788, -1.81642935385411]'
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
describe '#==' do
|
43
|
+
it 'returns true when objects coordinates are the same' do
|
44
|
+
other = Nominatim::Point.new(52.5487969264788, -1.81642935385411)
|
45
|
+
(point == other).should be_true
|
46
|
+
end
|
47
|
+
|
48
|
+
it 'returns false when objects coordinates are different' do
|
49
|
+
other = Nominatim::Point.new(-1.81642935385411, 52.5487969264788)
|
50
|
+
(point == other).should be_false
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Nominatim::Polygon do
|
4
|
+
|
5
|
+
let(:polygon) { Nominatim::Polygon.new([[-1.816513, 52.5487566], [-1.8164913, 52.548824], [-1.8164685, 52.5488213]]) }
|
6
|
+
|
7
|
+
it 'sets coordinates correctly' do
|
8
|
+
polygon.coordinates.first.lat.should eq -1.816513
|
9
|
+
polygon.coordinates.first.lon.should eq 52.5487566
|
10
|
+
end
|
11
|
+
|
12
|
+
describe '#coordinates' do
|
13
|
+
it 'retruns an array of coordinates' do
|
14
|
+
polygon.coordinates.each do |p|
|
15
|
+
p.should be_a Nominatim::Point
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,68 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Nominatim::Reverse do
|
4
|
+
|
5
|
+
let(:reverse) { Nominatim::Reverse.new }
|
6
|
+
|
7
|
+
it 'has no criteria set' do
|
8
|
+
reverse.criteria.should be_empty
|
9
|
+
end
|
10
|
+
|
11
|
+
it 'allows chaining of criterions' do
|
12
|
+
reverse.lat('37.733976').lon('-122.3912081').address_details(1)
|
13
|
+
reverse.criteria[:lat].should eq '37.733976'
|
14
|
+
reverse.criteria[:lon].should eq '-122.3912081'
|
15
|
+
reverse.criteria[:addressdetails].should eq 1
|
16
|
+
end
|
17
|
+
|
18
|
+
describe '#each' do
|
19
|
+
let(:reverse) { Nominatim::Reverse.new.lat('37.733976').lon('-122.3912081').address_details(1) }
|
20
|
+
|
21
|
+
before do
|
22
|
+
stub_get('/reverse').
|
23
|
+
with(query: { lat: '37.733976', lon: '-122.3912081', addressdetails: 1 }).
|
24
|
+
to_return(body: fixture('reverse.json'))
|
25
|
+
end
|
26
|
+
|
27
|
+
it 'iterates over the matching places' do
|
28
|
+
reverse.fetch.should be_a Nominatim::Place
|
29
|
+
end
|
30
|
+
|
31
|
+
it 'returns correct places' do
|
32
|
+
reverse.fetch.display_name.should eq '4900, 3rd Street, San Francisco, California, 94124, United States of America'
|
33
|
+
reverse.fetch.address.city.should eq 'San Francisco'
|
34
|
+
reverse.fetch.address.state.should eq 'California'
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
describe '#lat' do
|
39
|
+
it 'adds a latitude criterion' do
|
40
|
+
reverse.lat('37.733976')
|
41
|
+
reverse.criteria[:lat].should eq '37.733976'
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
describe '#lon' do
|
46
|
+
it 'adds a longitude criterion' do
|
47
|
+
reverse.lon('-122.3912081')
|
48
|
+
reverse.criteria[:lon].should eq '-122.3912081'
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
describe '#address_details' do
|
53
|
+
it 'adds an address details criterion' do
|
54
|
+
reverse.address_details(true)
|
55
|
+
reverse.criteria[:addressdetails].should eq 1
|
56
|
+
end
|
57
|
+
|
58
|
+
it 'sets 1 when set with true' do
|
59
|
+
reverse.address_details(true)
|
60
|
+
reverse.criteria[:addressdetails].should eq 1
|
61
|
+
end
|
62
|
+
|
63
|
+
it 'sets 0 when set with false' do
|
64
|
+
reverse.address_details(false)
|
65
|
+
reverse.criteria[:addressdetails].should eq 0
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
@@ -0,0 +1,140 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Nominatim::Search do
|
4
|
+
|
5
|
+
let(:search) { Nominatim::Search.new }
|
6
|
+
|
7
|
+
it 'has no criteria set' do
|
8
|
+
search.criteria.should be_empty
|
9
|
+
end
|
10
|
+
|
11
|
+
it 'allows chaining of criterions' do
|
12
|
+
search.query('Los Angeles').limit(1)
|
13
|
+
search.criteria[:q].should eq 'Los Angeles'
|
14
|
+
search.criteria[:limit].should eq 1
|
15
|
+
end
|
16
|
+
|
17
|
+
describe '#each' do
|
18
|
+
|
19
|
+
let(:search) { Nominatim::Search.new.query('Los Angeles').limit(1) }
|
20
|
+
|
21
|
+
before do
|
22
|
+
stub_get('/search').
|
23
|
+
with(query: { q: 'Los Angeles', limit: 1 }).
|
24
|
+
to_return(body: fixture('search.json'))
|
25
|
+
end
|
26
|
+
|
27
|
+
it 'iterates over the matching places' do
|
28
|
+
search.each do |place|
|
29
|
+
place.should be_a Nominatim::Place
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
it 'returns all matching places' do
|
34
|
+
search.count.should eq 1
|
35
|
+
end
|
36
|
+
|
37
|
+
it 'returns correct places' do
|
38
|
+
search.first.display_name.should eq 'Los Angeles, California, United States of America'
|
39
|
+
search.first.lat.should eq 34.0966764
|
40
|
+
search.first.lon.should eq -117.7196785
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
describe '#query' do
|
45
|
+
it 'adds a query criterion' do
|
46
|
+
search.query('Los Angeles')
|
47
|
+
search.criteria[:q].should eq 'Los Angeles'
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
describe '#country_codes' do
|
52
|
+
it 'adds a country codes criterion' do
|
53
|
+
search.country_codes('us')
|
54
|
+
search.criteria[:countrycodes].should eq 'us'
|
55
|
+
end
|
56
|
+
|
57
|
+
it 'adds all country codes when set with an array' do
|
58
|
+
search.country_codes(['us', 'ca'])
|
59
|
+
search.criteria[:countrycodes].should eq 'us,ca'
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
describe '#viewbox' do
|
64
|
+
it 'adds a viewbox criterion' do
|
65
|
+
search.viewbox(["52.5487442016602", "-1.81651306152344", "52.5488510131836", "-1.81634628772736"])
|
66
|
+
search.criteria[:viewbox].should eq "52.5487442016602,-1.81651306152344,52.5488510131836,-1.81634628772736"
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
describe '#bounded' do
|
71
|
+
it 'adds a bounded criterion' do
|
72
|
+
search.bounded(true)
|
73
|
+
search.criteria[:bounded].should eq 1
|
74
|
+
end
|
75
|
+
|
76
|
+
it 'sets 1 when set with true' do
|
77
|
+
search.bounded(true)
|
78
|
+
search.criteria[:bounded].should eq 1
|
79
|
+
end
|
80
|
+
|
81
|
+
it 'sets 0 when set with false' do
|
82
|
+
search.bounded(false)
|
83
|
+
search.criteria[:bounded].should eq 0
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
describe '#polygon' do
|
88
|
+
it 'adds a polygon criterion' do
|
89
|
+
search.polygon(true)
|
90
|
+
search.criteria[:polygon].should eq 1
|
91
|
+
end
|
92
|
+
|
93
|
+
it 'sets 1 when set with true' do
|
94
|
+
search.polygon(true)
|
95
|
+
search.criteria[:polygon].should eq 1
|
96
|
+
end
|
97
|
+
|
98
|
+
it 'sets 0 when set with false' do
|
99
|
+
search.polygon(false)
|
100
|
+
search.criteria[:polygon].should eq 0
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
104
|
+
describe '#address_details' do
|
105
|
+
it 'adds an address details criterion' do
|
106
|
+
search.address_details(true)
|
107
|
+
search.criteria[:addressdetails].should eq 1
|
108
|
+
end
|
109
|
+
|
110
|
+
it 'sets 1 when set with true' do
|
111
|
+
search.address_details(true)
|
112
|
+
search.criteria[:addressdetails].should eq 1
|
113
|
+
end
|
114
|
+
|
115
|
+
it 'sets 0 when set with false' do
|
116
|
+
search.address_details(false)
|
117
|
+
search.criteria[:addressdetails].should eq 0
|
118
|
+
end
|
119
|
+
end
|
120
|
+
|
121
|
+
describe '#exclude_place_ids' do
|
122
|
+
it 'excludes given place ids' do
|
123
|
+
search.exclude_place_ids('1')
|
124
|
+
search.criteria[:exclude_place_ids].should eq '1'
|
125
|
+
end
|
126
|
+
|
127
|
+
it 'adds all place ids when set with an array' do
|
128
|
+
search.exclude_place_ids(['1', '2', '3'])
|
129
|
+
search.criteria[:exclude_place_ids].should eq '1,2,3'
|
130
|
+
end
|
131
|
+
end
|
132
|
+
|
133
|
+
describe '#limit' do
|
134
|
+
it 'adds a limit criterion' do
|
135
|
+
search.limit(1)
|
136
|
+
search.criteria[:limit].should eq 1
|
137
|
+
end
|
138
|
+
end
|
139
|
+
|
140
|
+
end
|