libgeo 0.1.0

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.
@@ -0,0 +1,377 @@
1
+ # encoding: utf-8
2
+
3
+ require 'spec_helper'
4
+
5
+ describe Libgeo::Longitude do
6
+ let(:instance) { described_class.new(hemi, degrees, minutes, seconds) }
7
+
8
+ let(:hemi) { Libgeo::EAST }
9
+ let(:degrees) { 39 }
10
+ let(:minutes) { 20 }
11
+ let(:seconds) { 33.6444 }
12
+
13
+ let(:decimal) { 39.342679 }
14
+
15
+ describe '.decimal' do
16
+ subject { described_class.decimal(decimal) }
17
+
18
+ context 'when positive' do
19
+ it { expect(subject.hemisphere).to eql(hemi) }
20
+ it { expect(subject.degrees).to eql(degrees) }
21
+ it { expect(subject.minutes).to eql(minutes) }
22
+ it { expect(subject.seconds).to eql(seconds) }
23
+ end
24
+
25
+ context 'when negative' do
26
+ let(:decimal) { -39.342679 }
27
+
28
+ it { expect(subject.hemisphere).to eql(Libgeo::WEST) }
29
+ it { expect(subject.degrees).to eql(degrees) }
30
+ it { expect(subject.minutes).to eql(minutes) }
31
+ it { expect(subject.seconds).to eql(seconds) }
32
+ end
33
+ end
34
+
35
+ describe '.dms' do
36
+ subject { described_class.dms(dms) }
37
+
38
+ context 'with characters' do
39
+ context 'when positive' do
40
+ let(:dms) { '58°39′13.5 E' }
41
+
42
+ it { expect(subject.hemisphere).to eql(Libgeo::EAST) }
43
+ it { expect(subject.degrees).to eql(58) }
44
+ it { expect(subject.minutes).to eql(39) }
45
+ it { expect(subject.seconds).to eql(13.5) }
46
+ end
47
+
48
+ context 'when negative' do
49
+ let(:dms) { '58°39′13.5 W' }
50
+
51
+ it { expect(subject.hemisphere).to eql(Libgeo::WEST) }
52
+ it { expect(subject.degrees).to eql(58) }
53
+ it { expect(subject.minutes).to eql(39) }
54
+ it { expect(subject.seconds).to eql(13.5) }
55
+ end
56
+ end
57
+
58
+ context 'without characters' do
59
+ context 'when positive' do
60
+ let(:dms) { '58°39′13.5' }
61
+
62
+ it { expect(subject.hemisphere).to eql(Libgeo::EAST) }
63
+ it { expect(subject.degrees).to eql(58) }
64
+ it { expect(subject.minutes).to eql(39) }
65
+ it { expect(subject.seconds).to eql(13.5) }
66
+ end
67
+
68
+ context 'when negative' do
69
+ let(:dms) { '-58°39′13.5' }
70
+
71
+ it { expect(subject.hemisphere).to eql(Libgeo::WEST) }
72
+ it { expect(subject.degrees).to eql(58) }
73
+ it { expect(subject.minutes).to eql(39) }
74
+ it { expect(subject.seconds).to eql(13.5) }
75
+ end
76
+ end
77
+ end
78
+
79
+ describe '.nmea' do
80
+ subject { described_class.nmea(nmea) }
81
+
82
+ context 'with characters' do
83
+ context 'when positive' do
84
+ let(:nmea) { '03920.56074,E' }
85
+
86
+ it { expect(subject.hemisphere).to eql(Libgeo::EAST) }
87
+ it { expect(subject.degrees).to eql(39) }
88
+ it { expect(subject.minutes).to eql(20) }
89
+ it { expect(subject.seconds).to eql(33.6444) }
90
+ end
91
+
92
+ context 'when negative' do
93
+ let(:nmea) { '03920.56074,W' }
94
+
95
+ it { expect(subject.hemisphere).to eql(Libgeo::WEST) }
96
+ it { expect(subject.degrees).to eql(39) }
97
+ it { expect(subject.minutes).to eql(20) }
98
+ it { expect(subject.seconds).to eql(33.6444) }
99
+ end
100
+ end
101
+
102
+ context 'without characters' do
103
+ context 'when positive' do
104
+ let(:nmea) { '+03920.56074' }
105
+
106
+ it { expect(subject.hemisphere).to eql(Libgeo::EAST) }
107
+ it { expect(subject.degrees).to eql(39) }
108
+ it { expect(subject.minutes).to eql(20) }
109
+ it { expect(subject.seconds).to eql(33.6444) }
110
+ end
111
+
112
+ context 'when negative' do
113
+ let(:nmea) { '-03920.56074' }
114
+
115
+ it { expect(subject.hemisphere).to eql(Libgeo::WEST) }
116
+ it { expect(subject.degrees).to eql(39) }
117
+ it { expect(subject.minutes).to eql(20) }
118
+ it { expect(subject.seconds).to eql(33.6444) }
119
+ end
120
+ end
121
+ end
122
+ describe '.degrees_minutes' do
123
+ subject { described_class.degrees_minutes(degrees, 20.56074) }
124
+
125
+ context 'when positive' do
126
+ it { expect(subject.hemisphere).to eql(hemi) }
127
+ it { expect(subject.degrees).to eql(degrees) }
128
+ it { expect(subject.minutes).to eql(minutes) }
129
+ it { expect(subject.seconds).to eql(seconds) }
130
+ end
131
+
132
+ context 'when negative' do
133
+ let(:degrees) { -39 }
134
+
135
+ it { expect(subject.hemisphere).to eql(Libgeo::WEST) }
136
+ it { expect(subject.degrees).to eql(39) }
137
+ it { expect(subject.minutes).to eql(minutes) }
138
+ it { expect(subject.seconds).to eql(seconds) }
139
+ end
140
+ end
141
+
142
+ describe '#type' do
143
+ subject { instance.type }
144
+
145
+ it { expect(subject).to equal(:longitude) }
146
+ end
147
+
148
+ describe '#degrees' do
149
+ it_behaves_like 'Coordinate#degrees'
150
+ end
151
+
152
+ describe '#minutes' do
153
+ it_behaves_like 'Coordinate#minutes'
154
+ end
155
+
156
+ describe '#seconds' do
157
+ it_behaves_like 'Coordinate#seconds'
158
+ end
159
+
160
+ describe 'different inputs' do
161
+ it_behaves_like 'Coordinate#inputs' do
162
+ let(:hemisphere) { :E }
163
+ end
164
+ end
165
+
166
+ describe 'values validation' do
167
+ it_behaves_like 'Coordinate#validation' do
168
+ let(:max_degrees) { 180 }
169
+ end
170
+ end
171
+
172
+ describe '#hemisphere' do
173
+ subject { instance.hemisphere }
174
+
175
+ describe 'Eastern' do
176
+ context 'when symbol' do
177
+ it { expect(subject).to eql(:E) }
178
+ end
179
+
180
+ context 'when string' do
181
+ let(:hemi) { 'E' }
182
+
183
+ it { expect(subject).to eql(:E) }
184
+ end
185
+
186
+ context 'when direction' do
187
+ let(:hemi) { :> }
188
+
189
+ it { expect(subject).to eql(:E) }
190
+ end
191
+
192
+ context 'when word' do
193
+ let(:hemi) { 'east' }
194
+
195
+ it { expect(subject).to eql(:E) }
196
+ end
197
+ end
198
+
199
+ describe 'Western' do
200
+ context 'when symbol' do
201
+ let(:hemi) { Libgeo::WEST }
202
+
203
+ it { expect(subject).to eql(:W) }
204
+ end
205
+
206
+ context 'when string' do
207
+ let(:hemi) { 'W' }
208
+
209
+ it { expect(subject).to eql(:W) }
210
+ end
211
+
212
+ context 'when direction' do
213
+ let(:hemi) { :< }
214
+
215
+ it { expect(subject).to eql(:W) }
216
+ end
217
+
218
+ context 'when word' do
219
+ let(:hemi) { 'west' }
220
+
221
+ it { expect(subject).to eql(:W) }
222
+ end
223
+ end
224
+ end
225
+
226
+ describe '#north!' do
227
+ let(:hemi) { Libgeo::WEST }
228
+
229
+ it { expect { instance.north! }.to_not change { instance.hemisphere } }
230
+ end
231
+
232
+ describe '#south!' do
233
+ let(:hemi) { Libgeo::WEST }
234
+
235
+ it { expect { instance.south! }.to_not change { instance.hemisphere } }
236
+ end
237
+
238
+ describe '#west!' do
239
+ it { expect { instance.west! }.to change { instance.hemisphere }.from(:E).to(:W) }
240
+ end
241
+
242
+ describe '#east!' do
243
+ let(:hemi) { Libgeo::WEST }
244
+
245
+ it { expect { instance.east! }.to change { instance.hemisphere }.from(:W).to(:E) }
246
+ end
247
+
248
+ describe '#north?' do
249
+ subject { instance.north? }
250
+
251
+ context 'when east' do
252
+ it { expect(subject).to be_falsy }
253
+ end
254
+
255
+ context 'when west' do
256
+ let(:hemi) { Libgeo::WEST }
257
+
258
+ it { expect(subject).to be_falsy }
259
+ end
260
+ end
261
+
262
+ describe '#south?' do
263
+ subject { instance.south? }
264
+
265
+ context 'when east' do
266
+ it { expect(subject).to be_falsy }
267
+ end
268
+
269
+ context 'when west' do
270
+ let(:hemi) { Libgeo::WEST }
271
+
272
+ it { expect(subject).to be_falsy }
273
+ end
274
+ end
275
+
276
+ describe '#west?' do
277
+ subject { instance.west? }
278
+
279
+ context 'when east' do
280
+ it { expect(subject).to be_falsy }
281
+ end
282
+
283
+ context 'when west' do
284
+ let(:hemi) { Libgeo::WEST }
285
+
286
+ it { expect(subject).to be_truthy }
287
+ end
288
+ end
289
+
290
+ describe '#east?' do
291
+ subject { instance.east? }
292
+
293
+ context 'when east' do
294
+ it { expect(subject).to be_truthy }
295
+ end
296
+
297
+ context 'when west' do
298
+ let(:hemi) { Libgeo::WEST }
299
+
300
+ it { expect(subject).to be_falsy }
301
+ end
302
+ end
303
+
304
+ describe '#to_f' do
305
+ subject { instance.to_f }
306
+
307
+ context 'when east' do
308
+ it { expect(subject).to eql(decimal) }
309
+ end
310
+
311
+ context 'when west' do
312
+ let(:hemi) { Libgeo::WEST }
313
+
314
+ it { expect(subject).to eql(-decimal) }
315
+ end
316
+ end
317
+
318
+ describe '#to_hash' do
319
+ it_behaves_like 'Coordinate#to_hash'
320
+ end
321
+
322
+ describe '#to_dms' do
323
+ subject { instance.to_dms }
324
+
325
+ context 'when east' do
326
+ it { expect(subject).to eql(%[39°20′33.6444″E]) }
327
+ end
328
+
329
+ context 'when west' do
330
+ let(:hemi) { Libgeo::WEST }
331
+
332
+ it { expect(subject).to eql(%[39°20′33.6444″W]) }
333
+ end
334
+ end
335
+
336
+ describe '#to_nmea' do
337
+ subject { instance.to_nmea }
338
+
339
+ context 'when east' do
340
+ it { expect(subject).to eql('03920.56074,E') }
341
+ end
342
+
343
+ context 'when west' do
344
+ let(:hemi) { Libgeo::WEST }
345
+
346
+ it { expect(subject).to eql('03920.56074,W') }
347
+ end
348
+ end
349
+
350
+ describe '#to_s' do
351
+ context 'default format' do
352
+ subject { instance.to_s }
353
+
354
+ context 'when east' do
355
+ it { expect(subject).to eql(%[39°20′33.6444″E]) }
356
+ end
357
+
358
+ context 'when west' do
359
+ let(:hemi) { Libgeo::WEST }
360
+
361
+ it { expect(subject).to eql(%[39°20′33.6444″W]) }
362
+ end
363
+ end
364
+ end
365
+
366
+ describe '#inspect' do
367
+ subject { instance.inspect }
368
+ let(:expected) { "#<Libgeo::Longitude hemisphere=E degrees=39 minutes=20 seconds=33.6444>" }
369
+
370
+ it { expect(subject).to eql(expected) }
371
+ end
372
+
373
+ describe '#to_utm' do
374
+ pending 'TODO'
375
+ end
376
+
377
+ end
metadata ADDED
@@ -0,0 +1,114 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: libgeo
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Andrey Savchenko
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-10-14 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '1.5'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '1.5'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ description: Collection of geographical primitives
42
+ email:
43
+ - andrey@aejis.eu
44
+ executables: []
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - .gitignore
49
+ - .rspec
50
+ - .travis.yml
51
+ - Gemfile
52
+ - LICENSE.txt
53
+ - README.md
54
+ - Rakefile
55
+ - lib/libgeo.rb
56
+ - lib/libgeo/coordinate.rb
57
+ - lib/libgeo/coordinate/class_methods.rb
58
+ - lib/libgeo/coordinate/hemi_helpers.rb
59
+ - lib/libgeo/coordinate/presenters.rb
60
+ - lib/libgeo/formatter.rb
61
+ - lib/libgeo/formatter/compiler.rb
62
+ - lib/libgeo/formatter/evaluator.rb
63
+ - lib/libgeo/latitude.rb
64
+ - lib/libgeo/longitude.rb
65
+ - lib/libgeo/version.rb
66
+ - libgeo.gemspec
67
+ - spec/shared_examples/coordinate_attrs.rb
68
+ - spec/shared_examples/coordinate_inputs.rb
69
+ - spec/shared_examples/coordinate_presenters.rb
70
+ - spec/shared_examples/coordinate_validation.rb
71
+ - spec/spec_helper.rb
72
+ - spec/unit/libgeo/coordinate_spec.rb
73
+ - spec/unit/libgeo/formatter/compiler_spec.rb
74
+ - spec/unit/libgeo/formatter/evaluator_spec.rb
75
+ - spec/unit/libgeo/formatter_spec.rb
76
+ - spec/unit/libgeo/latitude_spec.rb
77
+ - spec/unit/libgeo/longitude_spec.rb
78
+ homepage: https://github.com/Ptico/libgeo
79
+ licenses:
80
+ - MIT
81
+ metadata: {}
82
+ post_install_message:
83
+ rdoc_options: []
84
+ require_paths:
85
+ - lib
86
+ required_ruby_version: !ruby/object:Gem::Requirement
87
+ requirements:
88
+ - - '>='
89
+ - !ruby/object:Gem::Version
90
+ version: '0'
91
+ required_rubygems_version: !ruby/object:Gem::Requirement
92
+ requirements:
93
+ - - '>='
94
+ - !ruby/object:Gem::Version
95
+ version: '0'
96
+ requirements: []
97
+ rubyforge_project:
98
+ rubygems_version: 2.0.14
99
+ signing_key:
100
+ specification_version: 4
101
+ summary: Collection of geographical primitives
102
+ test_files:
103
+ - spec/shared_examples/coordinate_attrs.rb
104
+ - spec/shared_examples/coordinate_inputs.rb
105
+ - spec/shared_examples/coordinate_presenters.rb
106
+ - spec/shared_examples/coordinate_validation.rb
107
+ - spec/spec_helper.rb
108
+ - spec/unit/libgeo/coordinate_spec.rb
109
+ - spec/unit/libgeo/formatter/compiler_spec.rb
110
+ - spec/unit/libgeo/formatter/evaluator_spec.rb
111
+ - spec/unit/libgeo/formatter_spec.rb
112
+ - spec/unit/libgeo/latitude_spec.rb
113
+ - spec/unit/libgeo/longitude_spec.rb
114
+ has_rdoc: