aixm 0.3.8 → 0.3.10

Sign up to get free protection for your applications and to get access to all the features.
Files changed (115) hide show
  1. checksums.yaml +4 -4
  2. checksums.yaml.gz.sig +1 -0
  3. data.tar.gz.sig +0 -0
  4. data/CHANGELOG.md +33 -3
  5. data/README.md +166 -56
  6. data/exe/ckmid +14 -0
  7. data/exe/mkmid +14 -0
  8. data/lib/aixm.rb +16 -6
  9. data/lib/aixm/association.rb +369 -0
  10. data/lib/aixm/classes.rb +43 -0
  11. data/lib/aixm/component/fato.rb +45 -53
  12. data/lib/aixm/component/frequency.rb +11 -12
  13. data/lib/aixm/component/geometry.rb +36 -38
  14. data/lib/aixm/component/geometry/arc.rb +2 -2
  15. data/lib/aixm/component/geometry/border.rb +6 -3
  16. data/lib/aixm/component/geometry/circle.rb +8 -2
  17. data/lib/aixm/component/geometry/point.rb +8 -2
  18. data/lib/aixm/component/helipad.rb +30 -38
  19. data/lib/aixm/component/layer.rb +28 -19
  20. data/lib/aixm/component/lighting.rb +12 -13
  21. data/lib/aixm/component/runway.rb +44 -48
  22. data/lib/aixm/{feature → component}/service.rb +37 -36
  23. data/lib/aixm/component/surface.rb +3 -3
  24. data/lib/aixm/component/timetable.rb +2 -2
  25. data/lib/aixm/component/{vertical_limits.rb → vertical_limit.rb} +12 -6
  26. data/lib/aixm/config.rb +2 -1
  27. data/lib/aixm/document.rb +27 -50
  28. data/lib/aixm/executables.rb +85 -0
  29. data/lib/aixm/feature.rb +13 -3
  30. data/lib/aixm/feature/address.rb +12 -13
  31. data/lib/aixm/feature/airport.rb +103 -128
  32. data/lib/aixm/feature/airspace.rb +44 -17
  33. data/lib/aixm/feature/navigational_aid.rb +7 -9
  34. data/lib/aixm/feature/navigational_aid/designated_point.rb +13 -15
  35. data/lib/aixm/feature/navigational_aid/dme.rb +11 -12
  36. data/lib/aixm/feature/navigational_aid/marker.rb +7 -3
  37. data/lib/aixm/feature/navigational_aid/ndb.rb +7 -3
  38. data/lib/aixm/feature/navigational_aid/tacan.rb +7 -3
  39. data/lib/aixm/feature/navigational_aid/vor.rb +23 -15
  40. data/lib/aixm/feature/obstacle.rb +29 -43
  41. data/lib/aixm/feature/obstacle_group.rb +37 -34
  42. data/lib/aixm/feature/organisation.rb +21 -5
  43. data/lib/aixm/feature/unit.rb +36 -46
  44. data/lib/aixm/memoize.rb +89 -0
  45. data/lib/aixm/object.rb +9 -0
  46. data/lib/aixm/payload_hash.rb +114 -0
  47. data/lib/aixm/refinements.rb +29 -76
  48. data/lib/aixm/shortcuts.rb +5 -42
  49. data/lib/aixm/version.rb +1 -1
  50. data/lib/aixm/xy.rb +1 -1
  51. data/schemas/ofmx/0/OFMX-Features.xsd +152 -20
  52. data/schemas/ofmx/0/OFMX-Snapshot.xsd +0 -5
  53. metadata +107 -156
  54. metadata.gz.sig +2 -0
  55. data/.github/workflows/test.yml +0 -26
  56. data/.gitignore +0 -6
  57. data/.ruby-version +0 -1
  58. data/.yardopts +0 -3
  59. data/Guardfile +0 -8
  60. data/aixm.gemspec +0 -35
  61. data/gems.rb +0 -3
  62. data/lib/aixm/component.rb +0 -6
  63. data/rakefile.rb +0 -36
  64. data/spec/factory.rb +0 -559
  65. data/spec/lib/aixm/a_spec.rb +0 -203
  66. data/spec/lib/aixm/component/fato_spec.rb +0 -267
  67. data/spec/lib/aixm/component/frequency_spec.rb +0 -74
  68. data/spec/lib/aixm/component/geometry/arc_spec.rb +0 -73
  69. data/spec/lib/aixm/component/geometry/border_spec.rb +0 -38
  70. data/spec/lib/aixm/component/geometry/circle_spec.rb +0 -68
  71. data/spec/lib/aixm/component/geometry/point_spec.rb +0 -37
  72. data/spec/lib/aixm/component/geometry_spec.rb +0 -316
  73. data/spec/lib/aixm/component/helipad_spec.rb +0 -193
  74. data/spec/lib/aixm/component/layer_spec.rb +0 -135
  75. data/spec/lib/aixm/component/lighting_spec.rb +0 -94
  76. data/spec/lib/aixm/component/runway_spec.rb +0 -479
  77. data/spec/lib/aixm/component/surface_spec.rb +0 -124
  78. data/spec/lib/aixm/component/timetable_spec.rb +0 -47
  79. data/spec/lib/aixm/component/vertical_limits_spec.rb +0 -94
  80. data/spec/lib/aixm/config_spec.rb +0 -41
  81. data/spec/lib/aixm/d_spec.rb +0 -150
  82. data/spec/lib/aixm/document_spec.rb +0 -1884
  83. data/spec/lib/aixm/errors_spec.rb +0 -14
  84. data/spec/lib/aixm/f_spec.rb +0 -85
  85. data/spec/lib/aixm/feature/address_spec.rb +0 -60
  86. data/spec/lib/aixm/feature/airport_spec.rb +0 -776
  87. data/spec/lib/aixm/feature/airspace_spec.rb +0 -394
  88. data/spec/lib/aixm/feature/navigational_aid/designated_point_spec.rb +0 -103
  89. data/spec/lib/aixm/feature/navigational_aid/dme_spec.rb +0 -98
  90. data/spec/lib/aixm/feature/navigational_aid/marker_spec.rb +0 -85
  91. data/spec/lib/aixm/feature/navigational_aid/ndb_spec.rb +0 -95
  92. data/spec/lib/aixm/feature/navigational_aid/tacan_spec.rb +0 -94
  93. data/spec/lib/aixm/feature/navigational_aid/vor_spec.rb +0 -251
  94. data/spec/lib/aixm/feature/navigational_aid_spec.rb +0 -52
  95. data/spec/lib/aixm/feature/obstacle_group_spec.rb +0 -330
  96. data/spec/lib/aixm/feature/obstacle_spec.rb +0 -284
  97. data/spec/lib/aixm/feature/organisation_spec.rb +0 -83
  98. data/spec/lib/aixm/feature/service_spec.rb +0 -59
  99. data/spec/lib/aixm/feature/unit_spec.rb +0 -238
  100. data/spec/lib/aixm/feature_spec.rb +0 -38
  101. data/spec/lib/aixm/p_spec.rb +0 -189
  102. data/spec/lib/aixm/refinements_spec.rb +0 -430
  103. data/spec/lib/aixm/version_spec.rb +0 -7
  104. data/spec/lib/aixm/w_spec.rb +0 -150
  105. data/spec/lib/aixm/xy_spec.rb +0 -180
  106. data/spec/lib/aixm/z_spec.rb +0 -94
  107. data/spec/macros/marking.rb +0 -12
  108. data/spec/macros/organisation.rb +0 -11
  109. data/spec/macros/remarks.rb +0 -12
  110. data/spec/macros/timetable.rb +0 -11
  111. data/spec/macros/xy.rb +0 -11
  112. data/spec/macros/z_qnh.rb +0 -11
  113. data/spec/sounds/failure.mp3 +0 -0
  114. data/spec/sounds/success.mp3 +0 -0
  115. data/spec/spec_helper.rb +0 -62
@@ -1,430 +0,0 @@
1
- require_relative '../../spec_helper'
2
-
3
- using AIXM::Refinements
4
-
5
- describe AIXM::Refinements do
6
-
7
- context Array do
8
- describe :to_digest do
9
- it "must digest single string" do
10
- _(%w(a).to_digest).must_equal "1f40fc92"
11
- end
12
-
13
- it "must digest double string" do
14
- _(%w(a b).to_digest).must_equal "3c075e5f"
15
- end
16
-
17
- it "must digest integer" do
18
- _([5].to_digest).must_equal "06df0537"
19
- end
20
-
21
- it "must digest nested array" do
22
- _([1, [2, 3]].to_digest).must_equal "e9609e81"
23
- end
24
-
25
- it "must digest float" do
26
- _([5.0].to_digest).must_equal "78fc651d"
27
- end
28
-
29
- it "must digest boolean" do
30
- _([true, false].to_digest).must_equal "79bdc67a"
31
- end
32
-
33
- it "must digest nil" do
34
- _([nil].to_digest).must_equal "cf83e135"
35
- end
36
- end
37
-
38
- describe :to_uuid do
39
- it "must digest single string" do
40
- _(%w(a).to_uuid).must_equal "0cc175b9-c0f1-b6a8-31c3-99e269772661"
41
- end
42
-
43
- it "must digest double string" do
44
- _(%w(a b).to_uuid).must_equal "d0726241-0206-76b1-4aa6-298ce6a18b21"
45
- end
46
-
47
- it "must digest integer" do
48
- _([5].to_uuid).must_equal "e4da3b7f-bbce-2345-d777-2b0674a318d5"
49
- end
50
-
51
- it "must digest nested array" do
52
- _([1, [2, 3]].to_uuid).must_equal "02b12e93-0c8b-cc7e-92e7-4ff5d96ce118"
53
- end
54
-
55
- it "must digest float" do
56
- _([5.0].to_uuid).must_equal "336669db-e720-233e-d557-7ddf81b653d3"
57
- end
58
-
59
- it "must digest boolean" do
60
- _([true, false].to_uuid).must_equal "215c2d45-b491-f5c8-15ac-e782ce450fdf"
61
- end
62
-
63
- it "must digest nil" do
64
- _([nil].to_uuid).must_equal "d41d8cd9-8f00-b204-e980-0998ecf8427e"
65
- end
66
- end
67
- end
68
-
69
- context Float do
70
- describe :to_dms do
71
- it "must convert +1. DD to DMS" do
72
- _(1.37595556.to_dms).must_equal %q(001°22'33.44")
73
- end
74
-
75
- it "must convert -1. DD to DMS" do
76
- _(-1.37595556.to_dms).must_equal %q(-001°22'33.44")
77
- end
78
-
79
- it "must convert +2. DD to DMS" do
80
- _(11.37595556.to_dms).must_equal %q(011°22'33.44")
81
- end
82
-
83
- it "must convert -2. DD to DMS" do
84
- _(-11.37595556.to_dms).must_equal %q(-011°22'33.44")
85
- end
86
-
87
- it "must convert +3. DD to DMS" do
88
- _(111.37595556.to_dms).must_equal %q(111°22'33.44")
89
- end
90
-
91
- it "must convert -3. DD to DMS" do
92
- _(-111.37595556.to_dms).must_equal %q(-111°22'33.44")
93
- end
94
-
95
- it "must convert DD to DMS with degrees only" do
96
- _(11.0.to_dms).must_equal %q(011°00'00.00")
97
- end
98
-
99
- it "must convert DD to DMS with degrees and minutes only" do
100
- _(11.36666667.to_dms).must_equal %q(011°22'00.00")
101
- end
102
-
103
- it "must convert DD to DMS with tenth of seconds only" do
104
- _(1.37594444.to_dms).must_equal %q(001°22'33.40")
105
- end
106
-
107
- it "must convert DD to DMS with whole seconds only" do
108
- _(1.37583333.to_dms).must_equal %q(001°22'33.00")
109
- end
110
-
111
- it "must convert DD to two zero padded DMS" do
112
- _(1.37595556.to_dms(2)).must_equal %q(01°22'33.44")
113
- end
114
-
115
- it "must convert DD to no zero padded DMS" do
116
- _(1.37595556.to_dms(0)).must_equal %q(1°22'33.44")
117
- end
118
- end
119
-
120
- describe :to_rad do
121
- it "must convert correctly" do
122
- _(0.0.to_rad).must_equal 0
123
- _(180.0.to_rad).must_equal Math::PI
124
- _(-123.0.to_rad).must_equal(-2.1467549799530254)
125
- end
126
- end
127
- end
128
-
129
- context Hash do
130
- describe :lookup do
131
- subject do
132
- { one: 1, two: 2, three: 3, four: :three }
133
- end
134
-
135
- it "must return value for key if key is present" do
136
- _(subject.lookup(:one)).must_equal 1
137
- end
138
-
139
- it "must return value if key is not found but value is present" do
140
- _(subject.lookup(1)).must_equal 1
141
- end
142
-
143
- it "must return value for key if both key and value are present" do
144
- _(subject.lookup(:three)).must_equal 3
145
- end
146
-
147
- it "returns default if neither key nor value are present" do
148
- _(subject.lookup(:foo, :default)).must_equal :default
149
- _(subject.lookup(:foo, nil)).must_be_nil
150
- end
151
-
152
- it "fails if neither key, value nor default are present" do
153
- _{ subject.lookup(:foo) }.must_raise KeyError
154
- end
155
- end
156
- end
157
-
158
- context Object do
159
- describe :then_if do
160
- subject do
161
- "foobar"
162
- end
163
-
164
- it "must return self if the condition is false" do
165
- _(subject.then_if(false) { |s| s.gsub(/o/, 'i') }).must_equal subject
166
- end
167
-
168
- it "must return apply the block if the condition is true" do
169
- _(subject.then_if(true) { |s| s.gsub(/o/, 'i') }).must_equal 'fiibar'
170
- end
171
- end
172
- end
173
-
174
- context Regexp do
175
- describe :decapture do
176
- it "should replace capture groups with non-capture groups" do
177
- _(/(foo) baz (bar)/.decapture).must_equal /(?-mix:(?:foo) baz (?:bar))/
178
- _(/(foo) baz (bar)/i.decapture).must_equal /(?i-mx:(?:foo) baz (?:bar))/
179
- end
180
-
181
- it "should replace named capture groups with non-capture groups" do
182
- _(/(?<a>foo) baz (?<b>bar)/.decapture).must_equal /(?-mix:(?:foo) baz (?:bar))/
183
- _(/(?<a>foo) baz (?<b>bar)/i.decapture).must_equal /(?i-mx:(?:foo) baz (?:bar))/
184
- end
185
-
186
- it "should not replace special groups" do
187
- _(/(?:foo) (?<=baz) bar/.decapture).must_equal /(?-mix:(?:foo) (?<=baz) bar)/
188
- end
189
-
190
- it "should not replace literal round brackets" do
191
- _(/\(foo\)/.decapture).must_equal /(?-mix:\(foo\))/
192
- end
193
-
194
- it "should replace literal backslash followed by literal round brackets" do
195
- _(/\\(foo\\)/.decapture).must_equal /(?-mix:\\(?:foo\\))/
196
- end
197
- end
198
- end
199
-
200
- context String do
201
- describe :indent do
202
- it "must indent single line string" do
203
- _('foobar'.indent(2)).must_equal ' foobar'
204
- end
205
-
206
- it "must indent multi line string" do
207
- _("foo\nbar".indent(2)).must_equal " foo\n bar"
208
- _("foo\nbar\n".indent(2)).must_equal " foo\n bar\n"
209
- end
210
- end
211
-
212
- context "hash function" do
213
- subject do
214
- <<~END
215
- <?xml version="1.0" encoding="utf-8"?>
216
- <OFMX-Snapshot region="LF">
217
- <Ser active="true" type="essential">
218
- <SerUid>
219
- <UniUid>
220
- <txtName>STRASBOURG APP</txtName>
221
- </UniUid>
222
- <codeType version="1" subversion="2">APP</codeType>
223
- <noSeq>1</noSeq>
224
- </SerUid>
225
- <Stt priority="1">
226
- <codeWorkHr>H24</codeWorkHr>
227
- </Stt>
228
- <Stt priority="2">
229
- <codeWorkHr>HX</codeWorkHr>
230
- </Stt>
231
- <txtRmk>aka STRASBOURG approche</txtRmk>
232
- </Ser>
233
- </OFMX-Snapshot>
234
- END
235
- end
236
-
237
- describe :payload_hash do
238
- it "must calculate and return the hash" do
239
- _(subject.payload_hash(region: 'LF', element: 'Ser')).must_equal "269b1f18-cabe-3c9e-1d71-48a7414a4cb9"
240
- end
241
-
242
- it "must upcase the region" do
243
- _(subject.payload_hash(region: 'lf', element: 'Ser')).must_equal "269b1f18-cabe-3c9e-1d71-48a7414a4cb9"
244
- end
245
-
246
- it "must ignore name extensions of named associations" do
247
- named_subject = subject.gsub(/<(.?)SerUid/, '<\1SerUidWithName')
248
- _(named_subject.payload_hash(region: 'LF', element: 'SerUidWithName')).must_equal subject.payload_hash(region: 'LF', element: 'SerUid')
249
- end
250
-
251
- it "must ignore mid attributes" do
252
- subject_with_mid = subject.sub(/(active="true")/, 'mid="123" \1')
253
- _(subject_with_mid.payload_hash(region: 'LF', element: 'Ser')).must_equal "269b1f18-cabe-3c9e-1d71-48a7414a4cb9"
254
- end
255
-
256
- it "must ignore source attributes" do
257
- subject_with_source = subject.sub(/(active="true")/, 'source="123" \1')
258
- _(subject_with_source.payload_hash(region: 'LF', element: 'Ser')).must_equal "269b1f18-cabe-3c9e-1d71-48a7414a4cb9"
259
- end
260
-
261
- it "must order the element arguments alphabetically" do
262
- subject_with_swap = subject.sub(/(active="true") (type="essential")/, '\2 \1')
263
- _(subject_with_swap.payload_hash(region: 'LF', element: 'Ser')).must_equal "269b1f18-cabe-3c9e-1d71-48a7414a4cb9"
264
- end
265
-
266
- it "must use the first non-declaration element in string by default" do
267
- _(subject.payload_hash(region: 'LF')).must_equal "fddbfb76-4868-0cd7-2afe-9f43e91867fb"
268
- end
269
- end
270
-
271
- describe :insert_payload_hash do
272
- it "must insert hash as mid attribute into element with arguments" do
273
- _(subject.insert_payload_hash(region: 'LF', element: 'Ser')).must_match /<Ser mid="269b1f18-cabe-3c9e-1d71-48a7414a4cb9" active/
274
- end
275
-
276
- it "must insert hash as mid attribute into element without arguments" do
277
- _(subject.insert_payload_hash(region: 'LF', element: 'txtRmk')).must_match /<txtRmk mid="8b23c36b-ff51-adfd-963f-03fcb012c0cf">/
278
- end
279
-
280
- it "must overwrite an already existing mid attribute" do
281
- subject_with_mid = subject.sub(/(active="true")/, 'mid="123" \1')
282
- _(subject_with_mid.insert_payload_hash(region: 'LF', element: 'Ser')).must_match /<Ser mid="269b1f18-cabe-3c9e-1d71-48a7414a4cb9" active/
283
- end
284
-
285
- it "must return string untouched if falsey region is passed" do
286
- _(subject.insert_payload_hash(region: nil)).must_equal subject
287
- end
288
- end
289
- end
290
-
291
- describe :to_dd do
292
- it "must convert +6.2 DMS to DD" do
293
- _(%q(12°34'56.78"N).to_dd).must_equal 12.58243888888889
294
- _(%q(12°34'56.78").to_dd).must_equal 12.58243888888889
295
- _(%q(12°34'56.78'').to_dd).must_equal 12.58243888888889
296
- _(%q(12 34 56.78).to_dd).must_equal 12.58243888888889
297
- _(%q(123456.78N).to_dd).must_equal 12.58243888888889
298
- end
299
-
300
- it "must convert -6.2 DMS to DD" do
301
- _(%q(12°34'56.78"S).to_dd).must_equal(-12.58243888888889)
302
- _(%q(-12°34'56.78").to_dd).must_equal(-12.58243888888889)
303
- _(%q(-12 34 56.78).to_dd).must_equal(-12.58243888888889)
304
- _(%q(123456.78S).to_dd).must_equal(-12.58243888888889)
305
- end
306
-
307
- it "must convert +7.2 DMS to DD" do
308
- _(%q(111°22'33.44"N).to_dd).must_equal 111.37595555555555
309
- _(%q(111°22'33.44").to_dd).must_equal 111.37595555555555
310
- _(%q(111 22 33.44).to_dd).must_equal 111.37595555555555
311
- _(%q(1112233.44N).to_dd).must_equal 111.37595555555555
312
- end
313
-
314
- it "must convert -7.2 DMS to DD" do
315
- _(%q(111°22'33.44"S).to_dd).must_equal(-111.37595555555555)
316
- _(%q(-111°22'33.44").to_dd).must_equal(-111.37595555555555)
317
- _(%q(-111 22 33.44).to_dd).must_equal(-111.37595555555555)
318
- _(%q(1112233.44S).to_dd).must_equal(-111.37595555555555)
319
- end
320
-
321
- it "must convert +6.1 DMS to DD" do
322
- _(%q(12°34'56.7"N).to_dd).must_equal 12.582416666666667
323
- _(%q(12°34'56.7").to_dd).must_equal 12.582416666666667
324
- _(%q(12 34 56.7).to_dd).must_equal 12.582416666666667
325
- _(%q(123456.7N).to_dd).must_equal 12.582416666666667
326
- end
327
-
328
- it "must convert -6.1 DMS to DD" do
329
- _(%q(12°34'56.7"S).to_dd).must_equal(-12.582416666666667)
330
- _(%q(-12°34'56.7").to_dd).must_equal(-12.582416666666667)
331
- _(%q(-12 34 56.7).to_dd).must_equal(-12.582416666666667)
332
- _(%q(123456.7S).to_dd).must_equal(-12.582416666666667)
333
- end
334
-
335
- it "must convert +7.1 DMS to DD" do
336
- _(%q(111°22'33.4"N).to_dd).must_equal 111.37594444444444
337
- _(%q(111°22'33.4").to_dd).must_equal 111.37594444444444
338
- _(%q(111 22 33.4).to_dd).must_equal 111.37594444444444
339
- _(%q(1112233.4N).to_dd).must_equal 111.37594444444444
340
- end
341
-
342
- it "must convert -7.1 DMS to DD" do
343
- _(%q(111°22'33.4"S).to_dd).must_equal(-111.37594444444444)
344
- _(%q(-111°22'33.4").to_dd).must_equal(-111.37594444444444)
345
- _(%q(-111 22 33.4).to_dd).must_equal(-111.37594444444444)
346
- _(%q(1112233.4S).to_dd).must_equal(-111.37594444444444)
347
- end
348
-
349
- it "must convert +6.0 DMS to DD" do
350
- _(%q(12°34'56"N).to_dd).must_equal 12.582222222222223
351
- _(%q(12°34'56").to_dd).must_equal 12.582222222222223
352
- _(%q(12 34 56).to_dd).must_equal 12.582222222222223
353
- _(%q(123456N).to_dd).must_equal 12.582222222222223
354
- end
355
-
356
- it "must convert -6.0 DMS to DD" do
357
- _(%q(12°34'56"S).to_dd).must_equal(-12.582222222222223)
358
- _(%q(-12°34'56").to_dd).must_equal(-12.582222222222223)
359
- _(%q(-12 34 56).to_dd).must_equal(-12.582222222222223)
360
- _(%q(123456S).to_dd).must_equal(-12.582222222222223)
361
- end
362
-
363
- it "must convert +7.0 DMS to DD" do
364
- _(%q(111°22'33"N).to_dd).must_equal 111.37583333333333
365
- _(%q(111°22'33").to_dd).must_equal 111.37583333333333
366
- _(%q(111 22 33).to_dd).must_equal 111.37583333333333
367
- _(%q(1112233N).to_dd).must_equal 111.37583333333333
368
- end
369
-
370
- it "must convert -7.0 DMS to DD" do
371
- _(%q(111°22'33"S).to_dd).must_equal(-111.37583333333333)
372
- _(%q(-111°22'33").to_dd).must_equal(-111.37583333333333)
373
- _(%q(-111 22 33).to_dd).must_equal(-111.37583333333333)
374
- _(%q(1112233S).to_dd).must_equal(-111.37583333333333)
375
- end
376
-
377
- it "must convert all cardinal directions to DD" do
378
- _(%q(111°22'33.44"N).to_dd).must_equal 111.37595555555555
379
- _(%q(111°22'33.44"E).to_dd).must_equal 111.37595555555555
380
- _(%q(111°22'33.44"S).to_dd).must_equal -111.37595555555555
381
- _(%q(111°22'33.44"W).to_dd).must_equal -111.37595555555555
382
- end
383
-
384
- it "must ignore minor typos when converting to DD" do
385
- _(%q(111°22'33,44"N).to_dd).must_equal 111.37595555555555
386
- _(%q(111°22'33.44"n).to_dd).must_equal 111.37595555555555
387
- _(%q(111°22"33.44"N).to_dd).must_equal 111.37595555555555
388
- _(%q(111°22'33.44'N).to_dd).must_equal 111.37595555555555
389
- _(%q(111°22'33.44" N).to_dd).must_equal 111.37595555555555
390
- _(%q(111° 22' 33.44" N).to_dd).must_equal 111.37595555555555
391
- _(%q(-111°22'33.44"S).to_dd).must_equal 111.37595555555555
392
- end
393
-
394
- it "must do all possible roundtrip conversions" do
395
- if ENV['SPEC_SCOPE'] == 'all'
396
- 2.times.with_index do |degrees|
397
- 60.times.with_index do |minutes|
398
- 60.times.with_index do |seconds|
399
- 100.times.with_index do |fractions|
400
- subject = %q(%03d°%02d'%02d.%02d") % [degrees, minutes, seconds, fractions]
401
- _(subject.to_dd.to_dms).must_equal subject
402
- end
403
- end
404
- end
405
- end
406
- else
407
- skip
408
- end
409
- end
410
- end
411
-
412
- describe :to_time do
413
- it "must convert valid dates and times" do
414
- subject = '2018-01-01 17:17 +00:00'
415
- _(subject.to_time).must_equal Time.parse(subject)
416
- end
417
-
418
- it "fails on invalid dates and times" do
419
- subject = '2018-01-77 17:17 +00:00'
420
- _{ subject.to_time }.must_raise ArgumentError
421
- end
422
- end
423
-
424
- describe :uptrans do
425
- it "must transliterate invalid characters" do
426
- _('DÉJÀ SCHÖN'.uptrans).must_equal 'DEJA SCHOEN'
427
- end
428
- end
429
- end
430
- end
@@ -1,7 +0,0 @@
1
- require_relative '../../spec_helper'
2
-
3
- describe AIXM do
4
- it "must be defined" do
5
- _(AIXM::VERSION).wont_be_nil
6
- end
7
- end
@@ -1,150 +0,0 @@
1
- require_relative '../../spec_helper'
2
-
3
- describe AIXM::W do
4
- subject do
5
- AIXM::Factory.w
6
- end
7
-
8
- describe :wgt= do
9
- it "fails on invalid values" do
10
- _([:foobar, -1]).wont_be_written_to subject, :wgt
11
- end
12
-
13
- it "converts Numeric to Float" do
14
- _(subject.tap { |s| s.wgt = 5 }.wgt).must_equal 5.0
15
- end
16
- end
17
-
18
- describe :unit= do
19
- it "fails on invalid values" do
20
- _([:foobar, 123]).wont_be_written_to subject, :unit
21
- end
22
-
23
- it "symbolizes and downcases values" do
24
- _(subject.tap { |s| s.unit = "KG" }.unit).must_equal :kg
25
- end
26
- end
27
-
28
- describe :to_kg do
29
- it "leaves kilograms untouched" do
30
- subject = AIXM.w(2, :kg)
31
- _(subject.to_kg).must_be_same_as subject
32
- end
33
-
34
- it "converts metric tonnes to kilograms" do
35
- _(AIXM.w(0.5, :t).to_kg).must_equal AIXM.w(500, :kg)
36
- end
37
-
38
- it "converts pound to kilograms" do
39
- _(AIXM.w(200, :lb).to_kg).must_equal AIXM.w(90.718474, :kg)
40
- end
41
-
42
- it "converts US tons to kilograms" do
43
- _(AIXM.w(0.5, :ton).to_kg).must_equal AIXM.w(453.59237, :kg)
44
- end
45
- end
46
-
47
- describe :to_t do
48
- it "leaves metric tonnes untouched" do
49
- subject = AIXM.w(2, :t)
50
- _(subject.to_t).must_be_same_as subject
51
- end
52
-
53
- it "converts kilograms to metric tonnes" do
54
- _(AIXM.w(10_000, :kg).to_t).must_equal AIXM.w(10, :t)
55
- end
56
-
57
- it "converts pound to metric tonnes" do
58
- _(AIXM.w(1000, :lb).to_t).must_equal AIXM.w(0.45359237, :t)
59
- end
60
-
61
- it "converts US tons to metric tonnes" do
62
- _(AIXM.w(1, :ton).to_t).must_equal AIXM.w(0.90718474, :t)
63
- end
64
- end
65
-
66
- describe :to_lb do
67
- it "leaves pound untouched" do
68
- subject = AIXM.w(2, :lb)
69
- _(subject.to_lb).must_be_same_as subject
70
- end
71
-
72
- it "converts kilograms to pound" do
73
- _(AIXM.w(50, :kg).to_lb).must_equal AIXM.w(110.2311311, :lb)
74
- end
75
-
76
- it "converts metric tonnes to pound" do
77
- _(AIXM.w(0.5, :t).to_lb).must_equal AIXM.w(1102.311311, :lb)
78
- end
79
-
80
- it "converts US tons to pound" do
81
- _(AIXM.w(0.5, :ton).to_lb).must_equal AIXM.w(1000.00000007, :lb)
82
- end
83
- end
84
-
85
- describe :to_ton do
86
- it "leaves US tons untouched" do
87
- subject = AIXM.w(2, :ton)
88
- _(subject.to_ton).must_be_same_as subject
89
- end
90
-
91
- it "converts kilograms to US tons" do
92
- _(AIXM.w(1000, :kg).to_ton).must_equal AIXM.w(1.10231131, :ton)
93
- end
94
-
95
- it "converts metrical tons to US tons" do
96
- _(AIXM.w(0.5, :t).to_ton).must_equal AIXM.w(0.55115566, :ton)
97
- end
98
-
99
- it "converts pound to US tons" do
100
- _(AIXM.w(3000, :lb).to_ton).must_equal AIXM.w(1.5, :ton)
101
- end
102
- end
103
-
104
- describe :<=> do
105
- it "recognizes objects with identical unit and weight as equal" do
106
- a = AIXM.w(123, :kg)
107
- b = AIXM.w(123.0, 'KG')
108
- _(a).must_equal b
109
- end
110
-
111
- it "recognizes objects with different units and converted weight as equal" do
112
- a = AIXM.w(123, :kg)
113
- b = AIXM.w(271.16858251, 'LB')
114
- _(a).must_equal b
115
- end
116
-
117
- it "recognizes objects with different units and identical weight as unequal" do
118
- a = AIXM.w(123, :kg)
119
- b = AIXM.w(123, :lb)
120
- _(a).wont_equal b
121
- end
122
-
123
- it "recognizes objects of different class as unequal" do
124
- a = AIXM.w(123, :kg)
125
- b = :oggy
126
- _(a).wont_equal b
127
- end
128
- end
129
-
130
- describe :hash do
131
- it "returns an integer" do
132
- _(subject.hash).must_be_instance_of Integer
133
- end
134
-
135
- it "allows for the use of instances as hash keys" do
136
- dupe = subject.dup
137
- _({ subject => true }[dupe]).must_equal true
138
- end
139
- end
140
-
141
- describe :zero? do
142
- it "returns true for zero weight" do
143
- _(subject.tap { |s| s.wgt = 0 }).must_be :zero?
144
- end
145
-
146
- it "returns false for non-zero weight" do
147
- _(subject.tap { |s| s.wgt = 1 }).wont_be :zero?
148
- end
149
- end
150
- end