geo_calc 0.6.1 → 0.7.1
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/Gemfile +3 -0
- data/README.textile +12 -0
- data/VERSION +1 -1
- data/geo_calc.gemspec +29 -6
- data/lib/geo_calc/calc/destination.rb +1 -1
- data/lib/geo_calc/calc/distance.rb +1 -1
- data/lib/geo_calc/calc/rhumb.rb +2 -2
- data/lib/geo_calc/calc.rb +20 -21
- data/lib/geo_calc/dms/converter.rb +106 -0
- data/lib/geo_calc/dms.rb +5 -0
- data/lib/geo_calc/extensions/array.rb +26 -0
- data/lib/geo_calc/extensions/hash.rb +23 -0
- data/lib/geo_calc/extensions/math.rb +6 -0
- data/lib/geo_calc/extensions/numeric.rb +24 -0
- data/lib/geo_calc/extensions/string.rb +44 -0
- data/lib/geo_calc/extensions/symbol.rb +9 -0
- data/lib/geo_calc/extensions.rb +4 -0
- data/lib/geo_calc/geo_point/class_methods.rb +15 -0
- data/lib/geo_calc/geo_point/core_extension.rb +11 -0
- data/lib/geo_calc/geo_point/shared.rb +29 -0
- data/lib/geo_calc/geo_point.rb +42 -40
- data/lib/geo_calc/pretty_print.rb +2 -2
- data/lib/geo_calc.rb +5 -0
- data/lib/geo_units/converter.rb +123 -0
- data/lib/geo_units/numeric_ext.rb +117 -0
- data/lib/geo_units.rb +21 -0
- data/spec/geo_calc/core_ext/numeric_geo_ext_spec.rb +48 -50
- data/spec/geo_calc/core_ext_spec.rb +49 -51
- data/spec/geo_calc/dms/converter_spec.rb +60 -0
- data/spec/geo_calc/geo_point/class_methods_spec.rb +31 -0
- data/spec/geo_calc/geo_point/initializer_spec.rb +148 -0
- data/spec/geo_calc/geo_point/lat_lon.rb +115 -0
- data/spec/geo_calc/geo_point_spec.rb +4 -274
- data/spec/geo_units/converter_spec.rb +57 -0
- metadata +56 -17
- data/lib/geo_calc/core_ext.rb +0 -318
- data/lib/geo_calc/geo.rb +0 -171
- data/spec/geo_calc/geo_spec.rb +0 -99
@@ -0,0 +1,148 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
# - www.movable-type.co.uk/scripts/latlong.html
|
4
|
+
describe GeoPoint do
|
5
|
+
describe '#initializer' do
|
6
|
+
describe '1 argument' do
|
7
|
+
describe 'single String' do
|
8
|
+
describe '50.1, 5.0 ' do
|
9
|
+
it 'should create a GeoPoint' do
|
10
|
+
p1 = GeoPoint.new "50.1, 5.0"
|
11
|
+
p1.should be_a(GeoPoint)
|
12
|
+
p1.lat.should == 50.1
|
13
|
+
p1.lon.should == 5.0
|
14
|
+
p1.unit.should == :degrees
|
15
|
+
p1.earth_radius_km.should == 6371
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
describe '(50.1, 5.0)' do
|
20
|
+
it 'should create a GeoPoint' do
|
21
|
+
p1 = GeoPoint.new "(50.1, 5.2)"
|
22
|
+
p1.should be_a(GeoPoint)
|
23
|
+
p1.lat.should == 50.1
|
24
|
+
p1.lon.should == 5.2
|
25
|
+
p1.unit.should == :degrees
|
26
|
+
p1.earth_radius_km.should == 6371
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
describe '58 38 38N, 003 04 12W' do
|
31
|
+
it 'should create a GeoPoint' do
|
32
|
+
p1 = GeoPoint.new "58 38 38N, 003 04 12W"
|
33
|
+
p1.should be_a(GeoPoint)
|
34
|
+
p1.lat.should be_within(0.5).of(58.38)
|
35
|
+
p1.lon.should be_within(0.5).of(-3)
|
36
|
+
p1.unit.should == :degrees
|
37
|
+
p1.earth_radius_km.should == 6371
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
describe '(58 38 38N, 003 04 12W)' do
|
42
|
+
it 'should create a GeoPoint' do
|
43
|
+
p1 = GeoPoint.new "(58 38 38N, 003 04 12W)"
|
44
|
+
p1.should be_a(GeoPoint)
|
45
|
+
p1.lat.should be_within(0.5).of(58.38)
|
46
|
+
p1.lon.should be_within(0.5).of(-3) # W is negative, then normalize
|
47
|
+
p1.unit.should == :degrees
|
48
|
+
p1.earth_radius_km.should == 6371
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
describe 'single Array' do
|
54
|
+
describe '2 Fixed numbers: 50,5 ' do
|
55
|
+
it 'should create a GeoPoint' do
|
56
|
+
p1 = GeoPoint.new [50, 5]
|
57
|
+
p1.should be_a(GeoPoint)
|
58
|
+
p1.lat.should == 50
|
59
|
+
p1.lon.should == 5
|
60
|
+
p1.unit.should == :degrees
|
61
|
+
p1.earth_radius_km.should == 6371
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
describe '2 Float numbers: 50.1, 5.0 ' do
|
66
|
+
it 'should create a GeoPoint' do
|
67
|
+
p1 = GeoPoint.new [50.1, 5.0]
|
68
|
+
p1.should be_a(GeoPoint)
|
69
|
+
p1.lat.should == 50.1
|
70
|
+
p1.lon.should == 5.0
|
71
|
+
p1.unit.should == :degrees
|
72
|
+
p1.earth_radius_km.should == 6371
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
describe 'single Hash' do
|
77
|
+
describe 'with: {:lat => 50.1, :lng => 5.1}' do
|
78
|
+
it 'should create a GeoPoint' do
|
79
|
+
p1 = GeoPoint.new :lat => 50.1, :lng => 5.1
|
80
|
+
p1.should be_a(GeoPoint)
|
81
|
+
p1.lat.should == 50.1
|
82
|
+
p1.lon.should == 5.1
|
83
|
+
p1.unit.should == :degrees
|
84
|
+
p1.earth_radius_km.should == 6371
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
describe 'with: {:lat => 50.1, :long => 5.1}' do
|
89
|
+
it 'should create a GeoPoint' do
|
90
|
+
p1 = GeoPoint.new :lat => 50.1, :long => 5.1
|
91
|
+
p1.should be_a(GeoPoint)
|
92
|
+
p1.lat.should == 50.1
|
93
|
+
p1.lon.should == 5.1
|
94
|
+
p1.unit.should == :degrees
|
95
|
+
p1.earth_radius_km.should == 6371
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
describe 'with: {:latitude => 50.1, :longitude => 5.1}' do
|
100
|
+
it 'should create a GeoPoint' do
|
101
|
+
p1 = GeoPoint.new :latitude => 50.1, :longitude => 5.1
|
102
|
+
p1.should be_a(GeoPoint)
|
103
|
+
p1.lat.should == 50.1
|
104
|
+
p1.lon.should == 5.1
|
105
|
+
p1.unit.should == :degrees
|
106
|
+
p1.earth_radius_km.should == 6371
|
107
|
+
end
|
108
|
+
end
|
109
|
+
end
|
110
|
+
end
|
111
|
+
end
|
112
|
+
|
113
|
+
describe 'with 2 arguments' do
|
114
|
+
describe '2 Fixed numbers (Fixnum)' do
|
115
|
+
it 'should create a GeoPoint' do
|
116
|
+
p1 = GeoPoint.new 50, 5
|
117
|
+
p1.should be_a(GeoPoint)
|
118
|
+
p1.lat.should == 50
|
119
|
+
p1.lon.should == 5
|
120
|
+
p1.unit.should == :degrees
|
121
|
+
p1.earth_radius_km.should == 6371
|
122
|
+
end
|
123
|
+
end
|
124
|
+
|
125
|
+
describe '2 Float numbers' do
|
126
|
+
it 'should create a GeoPoint' do
|
127
|
+
p1 = GeoPoint.new 50.1, 5.0
|
128
|
+
p1.should be_a(GeoPoint)
|
129
|
+
p1.lat.should == 50.1
|
130
|
+
p1.lon.should == 5.0
|
131
|
+
p1.unit.should == :degrees
|
132
|
+
p1.earth_radius_km.should == 6371
|
133
|
+
end
|
134
|
+
end
|
135
|
+
|
136
|
+
describe '2 Strings: "58 38 38N", "003 04 12W"' do
|
137
|
+
it 'should create a GeoPoint' do
|
138
|
+
p1 = GeoPoint.new "58 38 38N", "003 04 12W"
|
139
|
+
p1.should be_a(GeoPoint)
|
140
|
+
p1.lat.should be_within(0.5).of(58.38)
|
141
|
+
p1.lon.should be_within(0.5).of(-3)
|
142
|
+
p1.unit.should == :degrees
|
143
|
+
p1.earth_radius_km.should == 6371
|
144
|
+
end
|
145
|
+
end
|
146
|
+
end
|
147
|
+
end # initializer
|
148
|
+
end
|
@@ -0,0 +1,115 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
# - www.movable-type.co.uk/scripts/latlong.html
|
4
|
+
describe GeoPoint do
|
5
|
+
describe '#lat' do
|
6
|
+
before :each do
|
7
|
+
@p1 = GeoPoint.new 50, 5
|
8
|
+
end
|
9
|
+
|
10
|
+
it 'should return latitude' do
|
11
|
+
@p1.lat.should == 50
|
12
|
+
end
|
13
|
+
|
14
|
+
describe '#latitude (alias)' do
|
15
|
+
it 'should return latitude' do
|
16
|
+
@p1.latitude.should == 50
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
describe '#to_lat (alias)' do
|
21
|
+
it 'should return latitude' do
|
22
|
+
@p1.to_lat.should == 50
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
describe '#lat=' do
|
28
|
+
before :each do
|
29
|
+
@p1 = GeoPoint.new 50, 5
|
30
|
+
end
|
31
|
+
|
32
|
+
it 'should set new latitude' do
|
33
|
+
@p1.lat = 60
|
34
|
+
@p1.lat.should == 60
|
35
|
+
end
|
36
|
+
|
37
|
+
it 'should set new latitude -2' do
|
38
|
+
@p1.lat = -2
|
39
|
+
@p1.lat.should == -2
|
40
|
+
end
|
41
|
+
|
42
|
+
it 'should convert latitude -182 to -2' do
|
43
|
+
@p1.lat = -2
|
44
|
+
@p1.lat.should == -2
|
45
|
+
end
|
46
|
+
|
47
|
+
|
48
|
+
it 'should set new latitude within allowed range' do
|
49
|
+
@p1.lat = 520
|
50
|
+
@p1.lat.should be_between(0, 360)
|
51
|
+
end
|
52
|
+
|
53
|
+
describe '#latitude (alias)' do
|
54
|
+
it 'should set latitude' do
|
55
|
+
@p1.lat = 72
|
56
|
+
@p1.latitude.should == 72
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
describe '#lon' do
|
62
|
+
before :each do
|
63
|
+
@p1 = GeoPoint.new 5, 50
|
64
|
+
end
|
65
|
+
|
66
|
+
it 'should return longitude' do
|
67
|
+
@p1.lon.should == 50
|
68
|
+
end
|
69
|
+
|
70
|
+
it 'should return longitude (via lng)' do
|
71
|
+
@p1.lng.should == 50
|
72
|
+
end
|
73
|
+
|
74
|
+
describe '#longitude (alias)' do
|
75
|
+
it 'should return longitude' do
|
76
|
+
@p1.longitude.should == 50
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
describe '#to_lng (alias)' do
|
81
|
+
it 'should return latitude' do
|
82
|
+
@p1.to_lng.should == 50
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
describe '#lon=' do
|
88
|
+
before :each do
|
89
|
+
@p1 = GeoPoint.new 5, 50
|
90
|
+
end
|
91
|
+
|
92
|
+
it 'should set new longitude' do
|
93
|
+
@p1.lat.should == 5
|
94
|
+
@p1.lon = 60
|
95
|
+
@p1.lon.should == 60
|
96
|
+
end
|
97
|
+
|
98
|
+
it 'should return longitude (via lng)' do
|
99
|
+
@p1.lng = 70
|
100
|
+
@p1.lng.should == 70
|
101
|
+
end
|
102
|
+
|
103
|
+
it 'should set new latitude within allowed range' do
|
104
|
+
@p1.lon = 520
|
105
|
+
@p1.longitude.should be_between(-180, 180)
|
106
|
+
end
|
107
|
+
|
108
|
+
describe '#latitude (alias)' do
|
109
|
+
it 'should set latitude' do
|
110
|
+
@p1.longitude = 72
|
111
|
+
@p1.longitude.should == 72
|
112
|
+
end
|
113
|
+
end
|
114
|
+
end
|
115
|
+
end
|
@@ -1,151 +1,7 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
# - www.movable-type.co.uk/scripts/latlong.html
|
4
|
-
describe GeoPoint do
|
5
|
-
describe '#initializer' do
|
6
|
-
describe '1 argument' do
|
7
|
-
describe 'single String' do
|
8
|
-
describe '50.1, 5.0 ' do
|
9
|
-
it 'should create a GeoPoint' do
|
10
|
-
p1 = GeoPoint.new "50.1, 5.0"
|
11
|
-
p1.should be_a(GeoPoint)
|
12
|
-
p1.lat.should == 50.1
|
13
|
-
p1.lon.should == 5.0
|
14
|
-
p1.unit.should == :degrees
|
15
|
-
p1.radius.should == 6371
|
16
|
-
end
|
17
|
-
end
|
18
|
-
|
19
|
-
describe '(50.1, 5.0)' do
|
20
|
-
it 'should create a GeoPoint' do
|
21
|
-
p1 = GeoPoint.new "(50.1, 5.2)"
|
22
|
-
p1.should be_a(GeoPoint)
|
23
|
-
p1.lat.should == 50.1
|
24
|
-
p1.lon.should == 5.2
|
25
|
-
p1.unit.should == :degrees
|
26
|
-
p1.radius.should == 6371
|
27
|
-
end
|
28
|
-
end
|
29
|
-
|
30
|
-
describe '58 38 38N, 003 04 12W' do
|
31
|
-
it 'should create a GeoPoint' do
|
32
|
-
p1 = GeoPoint.new "58 38 38N, 003 04 12W"
|
33
|
-
p1.should be_a(GeoPoint)
|
34
|
-
p1.lat.should be_within(0.5).of(58.38)
|
35
|
-
p1.lon.should be_within(0.5).of(-3)
|
36
|
-
p1.unit.should == :degrees
|
37
|
-
p1.radius.should == 6371
|
38
|
-
end
|
39
|
-
end
|
40
|
-
|
41
|
-
describe '(58 38 38N, 003 04 12W)' do
|
42
|
-
it 'should create a GeoPoint' do
|
43
|
-
p1 = GeoPoint.new "(58 38 38N, 003 04 12W)"
|
44
|
-
p1.should be_a(GeoPoint)
|
45
|
-
p1.lat.should be_within(0.5).of(58.38)
|
46
|
-
p1.lon.should be_within(0.5).of(-3) # W is negative, then normalize
|
47
|
-
p1.unit.should == :degrees
|
48
|
-
p1.radius.should == 6371
|
49
|
-
end
|
50
|
-
end
|
51
|
-
end
|
52
|
-
|
53
|
-
describe 'single Array' do
|
54
|
-
describe '2 Fixed numbers: 50,5 ' do
|
55
|
-
it 'should create a GeoPoint' do
|
56
|
-
p1 = GeoPoint.new [50, 5]
|
57
|
-
p1.should be_a(GeoPoint)
|
58
|
-
p1.lat.should == 50
|
59
|
-
p1.lon.should == 5
|
60
|
-
p1.unit.should == :degrees
|
61
|
-
p1.radius.should == 6371
|
62
|
-
end
|
63
|
-
end
|
64
|
-
|
65
|
-
describe '2 Float numbers: 50.1, 5.0 ' do
|
66
|
-
it 'should create a GeoPoint' do
|
67
|
-
p1 = GeoPoint.new [50.1, 5.0]
|
68
|
-
p1.should be_a(GeoPoint)
|
69
|
-
p1.lat.should == 50.1
|
70
|
-
p1.lon.should == 5.0
|
71
|
-
p1.unit.should == :degrees
|
72
|
-
p1.radius.should == 6371
|
73
|
-
end
|
74
|
-
end
|
75
|
-
|
76
|
-
describe 'single Hash' do
|
77
|
-
describe 'with: {:lat => 50.1, :lng => 5.1}' do
|
78
|
-
it 'should create a GeoPoint' do
|
79
|
-
p1 = GeoPoint.new :lat => 50.1, :lng => 5.1
|
80
|
-
p1.should be_a(GeoPoint)
|
81
|
-
p1.lat.should == 50.1
|
82
|
-
p1.lon.should == 5.1
|
83
|
-
p1.unit.should == :degrees
|
84
|
-
p1.radius.should == 6371
|
85
|
-
end
|
86
|
-
end
|
87
|
-
|
88
|
-
describe 'with: {:lat => 50.1, :long => 5.1}' do
|
89
|
-
it 'should create a GeoPoint' do
|
90
|
-
p1 = GeoPoint.new :lat => 50.1, :long => 5.1
|
91
|
-
p1.should be_a(GeoPoint)
|
92
|
-
p1.lat.should == 50.1
|
93
|
-
p1.lon.should == 5.1
|
94
|
-
p1.unit.should == :degrees
|
95
|
-
p1.radius.should == 6371
|
96
|
-
end
|
97
|
-
end
|
98
|
-
|
99
|
-
describe 'with: {:latitude => 50.1, :longitude => 5.1}' do
|
100
|
-
it 'should create a GeoPoint' do
|
101
|
-
p1 = GeoPoint.new :latitude => 50.1, :longitude => 5.1
|
102
|
-
p1.should be_a(GeoPoint)
|
103
|
-
p1.lat.should == 50.1
|
104
|
-
p1.lon.should == 5.1
|
105
|
-
p1.unit.should == :degrees
|
106
|
-
p1.radius.should == 6371
|
107
|
-
end
|
108
|
-
end
|
109
|
-
end
|
110
|
-
end
|
111
|
-
end
|
112
|
-
|
113
|
-
describe 'with 2 arguments' do
|
114
|
-
describe '2 Fixed numbers (Fixnum)' do
|
115
|
-
it 'should create a GeoPoint' do
|
116
|
-
p1 = GeoPoint.new 50, 5
|
117
|
-
p1.should be_a(GeoPoint)
|
118
|
-
p1.lat.should == 50
|
119
|
-
p1.lon.should == 5
|
120
|
-
p1.unit.should == :degrees
|
121
|
-
p1.radius.should == 6371
|
122
|
-
end
|
123
|
-
end
|
124
|
-
|
125
|
-
describe '2 Float numbers' do
|
126
|
-
it 'should create a GeoPoint' do
|
127
|
-
p1 = GeoPoint.new 50.1, 5.0
|
128
|
-
p1.should be_a(GeoPoint)
|
129
|
-
p1.lat.should == 50.1
|
130
|
-
p1.lon.should == 5.0
|
131
|
-
p1.unit.should == :degrees
|
132
|
-
p1.radius.should == 6371
|
133
|
-
end
|
134
|
-
end
|
135
|
-
|
136
|
-
describe '2 Strings: "58 38 38N", "003 04 12W"' do
|
137
|
-
it 'should create a GeoPoint' do
|
138
|
-
p1 = GeoPoint.new "58 38 38N", "003 04 12W"
|
139
|
-
p1.should be_a(GeoPoint)
|
140
|
-
p1.lat.should be_within(0.5).of(58.38)
|
141
|
-
p1.lon.should be_within(0.5).of(-3)
|
142
|
-
p1.unit.should == :degrees
|
143
|
-
p1.radius.should == 6371
|
144
|
-
end
|
145
|
-
end
|
146
|
-
end
|
147
|
-
end # initializer
|
148
|
-
|
4
|
+
describe GeoPoint do
|
149
5
|
describe '#reverse_point' do
|
150
6
|
before :each do
|
151
7
|
@p = GeoPoint.new -2, 5
|
@@ -185,118 +41,6 @@ describe GeoPoint do
|
|
185
41
|
end
|
186
42
|
end
|
187
43
|
|
188
|
-
describe '#lat' do
|
189
|
-
before :each do
|
190
|
-
@p1 = GeoPoint.new 50, 5
|
191
|
-
end
|
192
|
-
|
193
|
-
it 'should return latitude' do
|
194
|
-
@p1.lat.should == 50
|
195
|
-
end
|
196
|
-
|
197
|
-
describe '#latitude (alias)' do
|
198
|
-
it 'should return latitude' do
|
199
|
-
@p1.latitude.should == 50
|
200
|
-
end
|
201
|
-
end
|
202
|
-
|
203
|
-
describe '#to_lat (alias)' do
|
204
|
-
it 'should return latitude' do
|
205
|
-
@p1.to_lat.should == 50
|
206
|
-
end
|
207
|
-
end
|
208
|
-
end
|
209
|
-
|
210
|
-
describe '#lat=' do
|
211
|
-
before :each do
|
212
|
-
@p1 = GeoPoint.new 50, 5
|
213
|
-
end
|
214
|
-
|
215
|
-
it 'should set new latitude' do
|
216
|
-
@p1.lat = 60
|
217
|
-
@p1.lat.should == 60
|
218
|
-
end
|
219
|
-
|
220
|
-
it 'should set new latitude -2' do
|
221
|
-
@p1.lat = -2
|
222
|
-
@p1.lat.should == -2
|
223
|
-
end
|
224
|
-
|
225
|
-
it 'should convert latitude -182 to -2' do
|
226
|
-
@p1.lat = -2
|
227
|
-
@p1.lat.should == -2
|
228
|
-
end
|
229
|
-
|
230
|
-
|
231
|
-
it 'should set new latitude within allowed range' do
|
232
|
-
@p1.lat = 520
|
233
|
-
@p1.lat.should be_between(0, 360)
|
234
|
-
end
|
235
|
-
|
236
|
-
describe '#latitude (alias)' do
|
237
|
-
it 'should set latitude' do
|
238
|
-
@p1.lat = 72
|
239
|
-
@p1.latitude.should == 72
|
240
|
-
end
|
241
|
-
end
|
242
|
-
end
|
243
|
-
|
244
|
-
describe '#lon' do
|
245
|
-
before :each do
|
246
|
-
@p1 = GeoPoint.new 5, 50
|
247
|
-
end
|
248
|
-
|
249
|
-
it 'should return longitude' do
|
250
|
-
@p1.lon.should == 50
|
251
|
-
end
|
252
|
-
|
253
|
-
it 'should return longitude (via lng)' do
|
254
|
-
@p1.lng.should == 50
|
255
|
-
end
|
256
|
-
|
257
|
-
describe '#longitude (alias)' do
|
258
|
-
it 'should return longitude' do
|
259
|
-
@p1.longitude.should == 50
|
260
|
-
end
|
261
|
-
end
|
262
|
-
|
263
|
-
describe '#to_lng (alias)' do
|
264
|
-
it 'should return latitude' do
|
265
|
-
@p1.to_lng.should == 50
|
266
|
-
end
|
267
|
-
end
|
268
|
-
end
|
269
|
-
|
270
|
-
describe '#lon=' do
|
271
|
-
before :each do
|
272
|
-
@p1 = GeoPoint.new 5, 50
|
273
|
-
end
|
274
|
-
|
275
|
-
it 'should set new longitude' do
|
276
|
-
@p1.lat.should == 5
|
277
|
-
@p1.lon = 60
|
278
|
-
@p1.lon.should == 60
|
279
|
-
end
|
280
|
-
|
281
|
-
it 'should return longitude (via lng)' do
|
282
|
-
@p1.lng = 70
|
283
|
-
@p1.lng.should == 70
|
284
|
-
end
|
285
|
-
|
286
|
-
it 'should set new latitude within allowed range' do
|
287
|
-
@p1.lon = 520
|
288
|
-
@p1.longitude.should be_between(-180, 180)
|
289
|
-
end
|
290
|
-
|
291
|
-
describe '#latitude (alias)' do
|
292
|
-
it 'should set latitude' do
|
293
|
-
@p1.longitude = 72
|
294
|
-
@p1.longitude.should == 72
|
295
|
-
end
|
296
|
-
end
|
297
|
-
end
|
298
|
-
|
299
|
-
|
300
44
|
describe '#[]' do
|
301
45
|
before :each do
|
302
46
|
@p1 = GeoPoint.new 50, 5
|
@@ -323,28 +67,14 @@ describe GeoPoint do
|
|
323
67
|
end
|
324
68
|
end
|
325
69
|
|
326
|
-
describe '#
|
70
|
+
describe '#to_a' do
|
327
71
|
before :each do
|
328
72
|
@p1 = GeoPoint.new 50, 5
|
329
73
|
end
|
330
74
|
|
331
75
|
it 'should return GeoPoint as an array depending on state of reverse_arr' do
|
332
|
-
@p1.
|
333
|
-
end
|
334
|
-
|
335
|
-
describe '#reverse_arr!' do
|
336
|
-
it 'should reverse the array returned by #to_arr to [lng, lat]' do
|
337
|
-
@p1.reverse_arr!
|
338
|
-
@p1.to_arr.should == [5, 50]
|
339
|
-
end
|
340
|
-
end
|
341
|
-
|
342
|
-
describe '#reverse_arr!' do
|
343
|
-
it 'should turn effect of #to_arr back to normal [lat, lng]' do
|
344
|
-
@p1.normal_arr!
|
345
|
-
@p1.to_arr.should == [50, 5]
|
346
|
-
end
|
347
|
-
end
|
76
|
+
@p1.to_a.should == [50, 5]
|
77
|
+
end
|
348
78
|
end
|
349
79
|
|
350
80
|
describe '#to_lat_lng' do
|
@@ -0,0 +1,57 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
class Converter
|
4
|
+
include GeoUnits::Converter
|
5
|
+
end
|
6
|
+
|
7
|
+
def converter
|
8
|
+
Converter.new
|
9
|
+
end
|
10
|
+
|
11
|
+
# - www.movable-type.co.uk/scripts/latlong.html
|
12
|
+
describe GeoUnits::Converter do
|
13
|
+
# deg, format, dp
|
14
|
+
describe '#to_lat' do
|
15
|
+
it 'should convert 58.3 to a latitude String in North direction' do
|
16
|
+
str_lat = converter.to_lat(58.3)
|
17
|
+
str_lat.should be_a(String)
|
18
|
+
expr = Regexp.escape "58".concat("\u00B0", "18", "\u2032", "00", "\u2033", "N")
|
19
|
+
str_lat.should match expr
|
20
|
+
end
|
21
|
+
|
22
|
+
it 'should convert -58.3 to a latitude String in South direction' do
|
23
|
+
str_lat = converter.to_lat(-58.3)
|
24
|
+
str_lat.should be_a(String)
|
25
|
+
expr = Regexp.escape "58".concat("\u00B0", "18", "\u2032", "00", "\u2033", "S")
|
26
|
+
str_lat.should match expr
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
# deg, format, dp
|
31
|
+
describe '#to_lon' do
|
32
|
+
it 'should convert 58.3 to a longitude String' do
|
33
|
+
str_lat = converter.to_lon(58.3)
|
34
|
+
str_lat.should be_a(String)
|
35
|
+
expr = Regexp.escape "58".concat("\u00B0", "18", "\u2032", "00", "\u2033", "E")
|
36
|
+
str_lat.should match expr
|
37
|
+
end
|
38
|
+
|
39
|
+
it 'should convert 58.3 to a longitude String' do
|
40
|
+
str_lat = converter.to_lon(-58.3)
|
41
|
+
str_lat.should be_a(String)
|
42
|
+
expr = Regexp.escape "58".concat("\u00B0", "18", "\u2032", "00", "\u2033", "W")
|
43
|
+
str_lat.should match expr
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
# Convert numeric degrees to deg/min/sec as a bearing (0º..360º)
|
48
|
+
# deg, format, dp
|
49
|
+
describe '#to_brng' do
|
50
|
+
it 'should convert 58.3 to a longitude String' do
|
51
|
+
brng = converter.to_brng(-58.3)
|
52
|
+
brng.to_f.should be_between(0, 360)
|
53
|
+
expr = Regexp.escape "301".concat("\u00B0", "42", "\u2032", "00")
|
54
|
+
brng.should match expr
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|