nominatim 0.0.2 → 0.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/CHANGELOG.md +12 -0
- data/lib/nominatim/place.rb +42 -6
- data/lib/nominatim/point.rb +30 -0
- data/lib/nominatim/polygon.rb +13 -0
- data/lib/nominatim/search.rb +1 -1
- data/lib/nominatim/version.rb +1 -1
- data/lib/nominatim.rb +2 -0
- data/spec/nominatim/place_spec.rb +13 -40
- data/spec/nominatim/point_spec.rb +53 -0
- data/spec/nominatim/polygon_spec.rb +19 -0
- data/spec/nominatim/search_spec.rb +2 -2
- metadata +7 -7
data/CHANGELOG.md
CHANGED
data/lib/nominatim/place.rb
CHANGED
|
@@ -7,29 +7,47 @@ module Nominatim
|
|
|
7
7
|
@attrs = attrs
|
|
8
8
|
end
|
|
9
9
|
|
|
10
|
+
# Return display name
|
|
11
|
+
#
|
|
12
|
+
# @return [String]
|
|
10
13
|
def display_name
|
|
11
14
|
@display_name ||= @attrs[:display_name]
|
|
12
15
|
end
|
|
13
16
|
|
|
17
|
+
# Return a class
|
|
18
|
+
#
|
|
19
|
+
# @return [String]
|
|
14
20
|
def class
|
|
15
21
|
@class ||= @attrs[:class]
|
|
16
22
|
end
|
|
17
23
|
|
|
24
|
+
# Return a type
|
|
25
|
+
#
|
|
26
|
+
# @return [String]
|
|
18
27
|
def type
|
|
19
28
|
@type ||= @attrs[:type]
|
|
20
29
|
end
|
|
21
30
|
|
|
31
|
+
# Return an address
|
|
32
|
+
#
|
|
33
|
+
# @return [Nominatim::Address]
|
|
22
34
|
def address
|
|
23
|
-
@address ||= Nominatim::Address.new(@attrs[:address])
|
|
35
|
+
@address ||= Nominatim::Address.new(@attrs[:address]) if @attrs[:address]
|
|
24
36
|
end
|
|
25
37
|
|
|
38
|
+
# Return a latitude
|
|
39
|
+
#
|
|
40
|
+
# @return [Float]
|
|
26
41
|
def lat
|
|
27
|
-
|
|
42
|
+
point.lat
|
|
28
43
|
end
|
|
29
44
|
alias latitude lat
|
|
30
45
|
|
|
46
|
+
# Return a longitude
|
|
47
|
+
#
|
|
48
|
+
# @return [Float]
|
|
31
49
|
def lon
|
|
32
|
-
|
|
50
|
+
point.lon
|
|
33
51
|
end
|
|
34
52
|
alias longitude lon
|
|
35
53
|
|
|
@@ -38,20 +56,38 @@ module Nominatim
|
|
|
38
56
|
end
|
|
39
57
|
alias bounding_box boundingbox
|
|
40
58
|
|
|
59
|
+
# Return a polygon
|
|
60
|
+
#
|
|
61
|
+
# @return [Nominatim::Polygon]
|
|
41
62
|
def polygonpoints
|
|
42
|
-
@polygonpoints ||= @attrs[:polygonpoints]
|
|
63
|
+
@polygonpoints ||= Nominatim::Polygon.new(@attrs[:polygonpoints]) if @attrs[:polygonpoints]
|
|
43
64
|
end
|
|
44
65
|
|
|
66
|
+
# Return a place id
|
|
67
|
+
#
|
|
68
|
+
# @return [Integer]
|
|
45
69
|
def place_id
|
|
46
|
-
@place_id ||= @attrs[:place_id]
|
|
70
|
+
@place_id ||= @attrs[:place_id].to_i if @attrs[:place_id]
|
|
47
71
|
end
|
|
48
72
|
|
|
73
|
+
# Return an OSM id
|
|
74
|
+
#
|
|
75
|
+
# @return [Integer]
|
|
49
76
|
def osm_id
|
|
50
|
-
@osm_id ||= @attrs[:osm_id]
|
|
77
|
+
@osm_id ||= @attrs[:osm_id].to_i if @attrs[:osm_id]
|
|
51
78
|
end
|
|
52
79
|
|
|
80
|
+
# Return an OSM type
|
|
81
|
+
#
|
|
82
|
+
# @return [String]
|
|
53
83
|
def osm_type
|
|
54
84
|
@osm_type ||= @attrs[:osm_type]
|
|
55
85
|
end
|
|
86
|
+
|
|
87
|
+
private
|
|
88
|
+
|
|
89
|
+
def point
|
|
90
|
+
@point ||= Nominatim::Point.new(@attrs[:lat], @attrs[:lon])
|
|
91
|
+
end
|
|
56
92
|
end
|
|
57
93
|
end
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
module Nominatim
|
|
2
|
+
class Point
|
|
3
|
+
attr_reader :lat, :lon
|
|
4
|
+
alias latitude lat
|
|
5
|
+
alias longitude lon
|
|
6
|
+
|
|
7
|
+
# @param lat [Float]
|
|
8
|
+
# @param lon [Float]
|
|
9
|
+
def initialize(lat, lon)
|
|
10
|
+
@lat, @lon = lat.to_f, lon.to_f if lat && lon
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
# @return [Array]
|
|
14
|
+
def to_a
|
|
15
|
+
[lat, lon]
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
# Return a string representation of the point
|
|
19
|
+
#
|
|
20
|
+
# @return [String]
|
|
21
|
+
def to_s
|
|
22
|
+
to_a.to_s
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
# @return [true, false]
|
|
26
|
+
def ==(other)
|
|
27
|
+
self.to_a == other.to_a
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
end
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
module Nominatim
|
|
2
|
+
class Polygon
|
|
3
|
+
attr_reader :coordinates
|
|
4
|
+
|
|
5
|
+
# @param coordinates [Array<Array<Float, String>>]
|
|
6
|
+
def initialize(coordinates)
|
|
7
|
+
@coordinates = []
|
|
8
|
+
coordinates.each do |c|
|
|
9
|
+
@coordinates.push(Nominatim::Point.new(c[0], c[1]))
|
|
10
|
+
end
|
|
11
|
+
end
|
|
12
|
+
end
|
|
13
|
+
end
|
data/lib/nominatim/search.rb
CHANGED
data/lib/nominatim/version.rb
CHANGED
data/lib/nominatim.rb
CHANGED
|
@@ -51,13 +51,8 @@ describe Nominatim::Place do
|
|
|
51
51
|
|
|
52
52
|
describe '#lat' do
|
|
53
53
|
it 'returns a latitude when set with lat' do
|
|
54
|
-
place = Nominatim::Place.new(lat: '52.5487969264788')
|
|
55
|
-
place.lat.should eq
|
|
56
|
-
end
|
|
57
|
-
|
|
58
|
-
it 'returns a latitude when set with latitude' do
|
|
59
|
-
place = Nominatim::Place.new(latitude: '52.5487969264788')
|
|
60
|
-
place.lat.should eq '52.5487969264788'
|
|
54
|
+
place = Nominatim::Place.new(lat: '52.5487969264788', lon: '-1.81642935385411')
|
|
55
|
+
place.lat.should eq 52.5487969264788
|
|
61
56
|
end
|
|
62
57
|
|
|
63
58
|
it 'returns nil when not set' do
|
|
@@ -68,13 +63,8 @@ describe Nominatim::Place do
|
|
|
68
63
|
|
|
69
64
|
describe '#latitude' do
|
|
70
65
|
it 'returns a latitude when set with lat' do
|
|
71
|
-
place = Nominatim::Place.new(lat: '52.5487969264788')
|
|
72
|
-
place.latitude.should eq
|
|
73
|
-
end
|
|
74
|
-
|
|
75
|
-
it 'returns a latitude when set with latitude' do
|
|
76
|
-
place = Nominatim::Place.new(latitude: '52.5487969264788')
|
|
77
|
-
place.latitude.should eq '52.5487969264788'
|
|
66
|
+
place = Nominatim::Place.new(lat: '52.5487969264788', lon: '-1.81642935385411')
|
|
67
|
+
place.latitude.should eq 52.5487969264788
|
|
78
68
|
end
|
|
79
69
|
|
|
80
70
|
it 'returns nil when not set' do
|
|
@@ -85,13 +75,8 @@ describe Nominatim::Place do
|
|
|
85
75
|
|
|
86
76
|
describe '#lon' do
|
|
87
77
|
it 'returns a longitude when set with lon' do
|
|
88
|
-
place = Nominatim::Place.new(lon: '-1.81642935385411')
|
|
89
|
-
place.lon.should eq
|
|
90
|
-
end
|
|
91
|
-
|
|
92
|
-
it 'returns a longitude when set with longitude' do
|
|
93
|
-
place = Nominatim::Place.new(longitude: '-1.81642935385411')
|
|
94
|
-
place.lon.should eq '-1.81642935385411'
|
|
78
|
+
place = Nominatim::Place.new(lat: '52.5487969264788', lon: '-1.81642935385411')
|
|
79
|
+
place.lon.should eq -1.81642935385411
|
|
95
80
|
end
|
|
96
81
|
|
|
97
82
|
it 'returns nil when not set' do
|
|
@@ -102,13 +87,8 @@ describe Nominatim::Place do
|
|
|
102
87
|
|
|
103
88
|
describe '#longitude' do
|
|
104
89
|
it 'returns a longitude when set with lon' do
|
|
105
|
-
place = Nominatim::Place.new(lon: '-1.81642935385411')
|
|
106
|
-
place.longitude.should eq
|
|
107
|
-
end
|
|
108
|
-
|
|
109
|
-
it 'returns a longitude when set with longitude' do
|
|
110
|
-
place = Nominatim::Place.new(longitude: '-1.81642935385411')
|
|
111
|
-
place.longitude.should eq '-1.81642935385411'
|
|
90
|
+
place = Nominatim::Place.new(lat: '52.5487969264788', lon: '-1.81642935385411')
|
|
91
|
+
place.longitude.should eq -1.81642935385411
|
|
112
92
|
end
|
|
113
93
|
|
|
114
94
|
it 'returns nil when not set' do
|
|
@@ -117,13 +97,6 @@ describe Nominatim::Place do
|
|
|
117
97
|
end
|
|
118
98
|
end
|
|
119
99
|
|
|
120
|
-
# describe '#coordinates' do
|
|
121
|
-
# it 'returns coordinates when set with lat and lon' do
|
|
122
|
-
# place = Nominatim::Place.new(lat: '52.5487969264788', lon: '-1.81642935385411')
|
|
123
|
-
# place.coordinates.should eq ['52.5487969264788', '-1.81642935385411']
|
|
124
|
-
# end
|
|
125
|
-
# end
|
|
126
|
-
|
|
127
100
|
describe '#boundingbox' do
|
|
128
101
|
it 'returns a boundingbox when set with boundingbox' do
|
|
129
102
|
place = Nominatim::Place.new(boundingbox: ["52.5487442016602", "52.5488510131836", "-1.81651306152344", "-1.81634628772736"])
|
|
@@ -151,7 +124,7 @@ describe Nominatim::Place do
|
|
|
151
124
|
describe '#polygonpoints' do
|
|
152
125
|
it 'returns polygon points when set with polygonpoints' do
|
|
153
126
|
place = Nominatim::Place.new(polygonpoints: [["-1.816513", "52.5487566"], ["-1.8164913", "52.548824"], ["-1.8164685", "52.5488213"]])
|
|
154
|
-
place.polygonpoints.should
|
|
127
|
+
place.polygonpoints.should be_a Nominatim::Polygon
|
|
155
128
|
end
|
|
156
129
|
|
|
157
130
|
it 'returns nil when not set' do
|
|
@@ -163,7 +136,7 @@ describe Nominatim::Place do
|
|
|
163
136
|
describe '#place_id' do
|
|
164
137
|
it 'returns a place id when set with place_id' do
|
|
165
138
|
place = Nominatim::Place.new(place_id: '84327444')
|
|
166
|
-
place.place_id.should eq
|
|
139
|
+
place.place_id.should eq 84327444
|
|
167
140
|
end
|
|
168
141
|
|
|
169
142
|
it 'returns nil when not set' do
|
|
@@ -173,9 +146,9 @@ describe Nominatim::Place do
|
|
|
173
146
|
end
|
|
174
147
|
|
|
175
148
|
describe '#osm_id' do
|
|
176
|
-
it 'returns
|
|
149
|
+
it 'returns an osm id when set with osm_id' do
|
|
177
150
|
place = Nominatim::Place.new(osm_id: '90394480')
|
|
178
|
-
place.osm_id.should eq
|
|
151
|
+
place.osm_id.should eq 90394480
|
|
179
152
|
end
|
|
180
153
|
|
|
181
154
|
it 'returns nil when not set' do
|
|
@@ -185,7 +158,7 @@ describe Nominatim::Place do
|
|
|
185
158
|
end
|
|
186
159
|
|
|
187
160
|
describe '#osm_type' do
|
|
188
|
-
it 'returns
|
|
161
|
+
it 'returns an osm type when set with osm_type' do
|
|
189
162
|
place = Nominatim::Place.new(osm_type: 'way')
|
|
190
163
|
place.osm_type.should eq 'way'
|
|
191
164
|
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
|
|
@@ -36,8 +36,8 @@ describe Nominatim::Search do
|
|
|
36
36
|
|
|
37
37
|
it 'returns correct places' do
|
|
38
38
|
search.first.display_name.should eq 'Los Angeles, California, United States of America'
|
|
39
|
-
search.first.lat.should eq
|
|
40
|
-
search.first.lon.should eq
|
|
39
|
+
search.first.lat.should eq 34.0966764
|
|
40
|
+
search.first.lon.should eq -117.7196785
|
|
41
41
|
end
|
|
42
42
|
end
|
|
43
43
|
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: nominatim
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.0.
|
|
4
|
+
version: 0.0.3
|
|
5
5
|
prerelease:
|
|
6
6
|
platform: ruby
|
|
7
7
|
authors:
|
|
@@ -144,6 +144,8 @@ files:
|
|
|
144
144
|
- lib/nominatim/client.rb
|
|
145
145
|
- lib/nominatim/configuration.rb
|
|
146
146
|
- lib/nominatim/place.rb
|
|
147
|
+
- lib/nominatim/point.rb
|
|
148
|
+
- lib/nominatim/polygon.rb
|
|
147
149
|
- lib/nominatim/response/parse_json.rb
|
|
148
150
|
- lib/nominatim/search.rb
|
|
149
151
|
- lib/nominatim/version.rb
|
|
@@ -152,6 +154,8 @@ files:
|
|
|
152
154
|
- spec/nominatim/address_spec.rb
|
|
153
155
|
- spec/nominatim/client_spec.rb
|
|
154
156
|
- spec/nominatim/place_spec.rb
|
|
157
|
+
- spec/nominatim/point_spec.rb
|
|
158
|
+
- spec/nominatim/polygon_spec.rb
|
|
155
159
|
- spec/nominatim/search_spec.rb
|
|
156
160
|
- spec/nominatim_spec.rb
|
|
157
161
|
- spec/spec_helper.rb
|
|
@@ -167,18 +171,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
|
167
171
|
- - ! '>='
|
|
168
172
|
- !ruby/object:Gem::Version
|
|
169
173
|
version: '0'
|
|
170
|
-
segments:
|
|
171
|
-
- 0
|
|
172
|
-
hash: -449881262904296726
|
|
173
174
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
174
175
|
none: false
|
|
175
176
|
requirements:
|
|
176
177
|
- - ! '>='
|
|
177
178
|
- !ruby/object:Gem::Version
|
|
178
179
|
version: '0'
|
|
179
|
-
segments:
|
|
180
|
-
- 0
|
|
181
|
-
hash: -449881262904296726
|
|
182
180
|
requirements: []
|
|
183
181
|
rubyforge_project:
|
|
184
182
|
rubygems_version: 1.8.23
|
|
@@ -190,6 +188,8 @@ test_files:
|
|
|
190
188
|
- spec/nominatim/address_spec.rb
|
|
191
189
|
- spec/nominatim/client_spec.rb
|
|
192
190
|
- spec/nominatim/place_spec.rb
|
|
191
|
+
- spec/nominatim/point_spec.rb
|
|
192
|
+
- spec/nominatim/polygon_spec.rb
|
|
193
193
|
- spec/nominatim/search_spec.rb
|
|
194
194
|
- spec/nominatim_spec.rb
|
|
195
195
|
- spec/spec_helper.rb
|