aixm 0.1.3 → 0.2.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.
Files changed (54) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +14 -0
  3. data/README.md +91 -11
  4. data/lib/aixm.rb +10 -0
  5. data/lib/aixm/base.rb +10 -0
  6. data/lib/aixm/component/base.rb +1 -1
  7. data/lib/aixm/component/class_layer.rb +0 -3
  8. data/lib/aixm/component/geometry.rb +0 -3
  9. data/lib/aixm/component/geometry/arc.rb +4 -8
  10. data/lib/aixm/component/geometry/base.rb +8 -0
  11. data/lib/aixm/component/geometry/border.rb +3 -8
  12. data/lib/aixm/component/geometry/circle.rb +5 -9
  13. data/lib/aixm/component/geometry/point.rb +6 -13
  14. data/lib/aixm/component/schedule.rb +8 -10
  15. data/lib/aixm/component/vertical_limits.rb +1 -4
  16. data/lib/aixm/document.rb +9 -6
  17. data/lib/aixm/f.rb +41 -0
  18. data/lib/aixm/feature/airspace.rb +5 -9
  19. data/lib/aixm/feature/base.rb +6 -0
  20. data/lib/aixm/feature/navigational_aid/base.rb +46 -0
  21. data/lib/aixm/feature/navigational_aid/designated_point.rb +69 -0
  22. data/lib/aixm/feature/navigational_aid/dme.rb +54 -0
  23. data/lib/aixm/feature/navigational_aid/marker.rb +41 -0
  24. data/lib/aixm/feature/navigational_aid/ndb.rb +56 -0
  25. data/lib/aixm/feature/navigational_aid/tacan.rb +54 -0
  26. data/lib/aixm/feature/navigational_aid/vor.rb +92 -0
  27. data/lib/aixm/refinements.rb +23 -2
  28. data/lib/aixm/shortcuts.rb +12 -5
  29. data/lib/aixm/version.rb +1 -1
  30. data/lib/aixm/xy.rb +9 -6
  31. data/lib/aixm/z.rb +22 -11
  32. data/spec/factory.rb +87 -4
  33. data/spec/lib/aixm/component/class_layer_spec.rb +6 -6
  34. data/spec/lib/aixm/component/geometry/arc_spec.rb +16 -16
  35. data/spec/lib/aixm/component/geometry/border_spec.rb +4 -4
  36. data/spec/lib/aixm/component/geometry/circle_spec.rb +10 -10
  37. data/spec/lib/aixm/component/geometry/point_spec.rb +4 -4
  38. data/spec/lib/aixm/component/geometry_spec.rb +21 -21
  39. data/spec/lib/aixm/component/schedule_spec.rb +6 -6
  40. data/spec/lib/aixm/component/vertical_limits_spec.rb +18 -18
  41. data/spec/lib/aixm/document_spec.rb +220 -30
  42. data/spec/lib/aixm/f_spec.rb +58 -0
  43. data/spec/lib/aixm/feature/airspace_spec.rb +5 -5
  44. data/spec/lib/aixm/feature/navigational_aid/base_spec.rb +37 -0
  45. data/spec/lib/aixm/feature/navigational_aid/designated_point_spec.rb +43 -0
  46. data/spec/lib/aixm/feature/navigational_aid/dme_spec.rb +43 -0
  47. data/spec/lib/aixm/feature/navigational_aid/marker_spec.rb +44 -0
  48. data/spec/lib/aixm/feature/navigational_aid/ndb_spec.rb +54 -0
  49. data/spec/lib/aixm/feature/navigational_aid/tacan_spec.rb +43 -0
  50. data/spec/lib/aixm/feature/navigational_aid/vor_spec.rb +58 -0
  51. data/spec/lib/aixm/refinements_spec.rb +27 -0
  52. data/spec/lib/aixm/xy_spec.rb +29 -23
  53. data/spec/lib/aixm/z_spec.rb +33 -17
  54. metadata +29 -2
@@ -0,0 +1,58 @@
1
+ require_relative '../../spec_helper'
2
+
3
+ describe AIXM::F do
4
+ describe :initialize do
5
+ it "must parse valid unit" do
6
+ subject = AIXM.f(123.35, :mhz)
7
+ subject.freq.must_equal 123.35
8
+ subject.unit.must_equal :mhz
9
+ end
10
+
11
+ it "won't parse invalid unit" do
12
+ -> { AIXM.f(123.35, :foo) }.must_raise ArgumentError
13
+ end
14
+ end
15
+
16
+ describe :to_digest do
17
+ it "must return digest of payload" do
18
+ AIXM.f(111, :mhz).to_digest.must_equal 779608518
19
+ end
20
+ end
21
+
22
+ describe :== do
23
+ it "recognizes objects with identical frequency and unit as equal" do
24
+ a = AIXM.f(123.0, :mhz)
25
+ b = AIXM.f(123, 'MHZ')
26
+ a.must_equal b
27
+ end
28
+
29
+ it "recognizes objects with different frequency or unit as unequal" do
30
+ a = AIXM.f(123.35, :mhz)
31
+ b = AIXM.f(123.35, :khz)
32
+ a.wont_equal b
33
+ end
34
+
35
+ it "recognizes objects of different class as unequal" do
36
+ a = AIXM.f(123.35, :mhz)
37
+ b = :oggy
38
+ a.wont_equal b
39
+ end
40
+ end
41
+
42
+ describe :between? do
43
+ subject do
44
+ AIXM.f(100, :mhz)
45
+ end
46
+
47
+ it "detect frequencies within a frequency band" do
48
+ subject.between?(90, 110, :mhz).must_equal true
49
+ subject.between?(90, 100, :mhz).must_equal true
50
+ subject.between?(100.0, 100.1, :mhz).must_equal true
51
+ end
52
+
53
+ it "detect frequencies outside of a frequency band" do
54
+ subject.between?(90, 110, :khz).must_equal false
55
+ subject.between?(90, 95, :mhz).must_equal false
56
+ end
57
+ end
58
+ end
@@ -3,7 +3,7 @@ require_relative '../../../spec_helper'
3
3
  describe AIXM::Feature::Airspace do
4
4
  context "incomplete" do
5
5
  subject do
6
- AIXM::Feature::Airspace.new(name: 'foobar', type: 'D')
6
+ AIXM.airspace(name: 'foobar', type: 'D')
7
7
  end
8
8
 
9
9
  describe :complete? do
@@ -27,14 +27,14 @@ describe AIXM::Feature::Airspace do
27
27
 
28
28
  describe :to_digest do
29
29
  it "must return digest of payload" do
30
- subject.to_digest.must_equal 202650074
30
+ subject.to_digest.must_equal 367297292
31
31
  end
32
32
  end
33
33
 
34
34
  describe :to_xml do
35
35
  it "must build correct XML with OFM extensions" do
36
36
  digest = subject.to_digest
37
- subject.to_xml(:OFM).must_equal <<~"END"
37
+ subject.to_xml(:ofm).must_equal <<~"END"
38
38
  <!-- Airspace: [D] POLYGON AIRSPACE -->
39
39
  <Ase xt_classLayersAvail="false">
40
40
  <AseUid mid="#{digest}" newEntity="true">
@@ -112,14 +112,14 @@ describe AIXM::Feature::Airspace do
112
112
 
113
113
  describe :to_digest do
114
114
  it "must return digest of payload" do
115
- subject.to_digest.must_equal 880919413
115
+ subject.to_digest.must_equal 481196243
116
116
  end
117
117
  end
118
118
 
119
119
  describe :to_xml do
120
120
  it "must build correct XML with OFM extensions" do
121
121
  digest = subject.to_digest
122
- subject.to_xml(:OFM).must_equal <<~"END"
122
+ subject.to_xml(:ofm).must_equal <<~"END"
123
123
  <!-- Airspace: [D] POLYGON AIRSPACE -->
124
124
  <Ase xt_classLayersAvail="true">
125
125
  <AseUid mid="#{digest}" newEntity="true">
@@ -0,0 +1,37 @@
1
+ require_relative '../../../../spec_helper'
2
+
3
+ describe AIXM::Feature::NavigationalAid::Base do
4
+ let :base do
5
+ AIXM::Feature::NavigationalAid::Base
6
+ end
7
+
8
+ describe :initialize do
9
+ it "won't accept invalid arguments" do
10
+ -> { base.send(:new, id: 'id', name: 'name', xy: 0) }.must_raise ArgumentError
11
+ -> { base.send(:new, id: 'id', name: 'name', xy: AIXM::Factory.xy, z: 0) }.must_raise ArgumentError
12
+ -> { base.send(:new, id: 'id', name: 'name', xy: AIXM::Factory.xy, z: AIXM.z(1, :qne)) }.must_raise ArgumentError
13
+ end
14
+
15
+ context "downcase attributes" do
16
+ subject do
17
+ base.send(:new, id: 'id', name: 'name', xy: AIXM::Factory.xy)
18
+ end
19
+
20
+ it "upcases ID" do
21
+ subject.id.must_equal 'ID'
22
+ end
23
+
24
+ it "upcases name" do
25
+ subject.name.must_equal 'NAME'
26
+ end
27
+ end
28
+ end
29
+
30
+ describe :to_digest do
31
+ it "must return digest of payload" do
32
+ subject = base.send(:new, id: 'id', name: 'name', xy: AIXM::Factory.xy, z: AIXM.z(100, :qnh))
33
+ subject.to_digest.must_equal 711143170
34
+ end
35
+ end
36
+
37
+ end
@@ -0,0 +1,43 @@
1
+ require_relative '../../../../spec_helper'
2
+
3
+ describe AIXM::Feature::NavigationalAid::DesignatedPoint do
4
+ context "complete" do
5
+ subject do
6
+ AIXM::Factory.designated_point
7
+ end
8
+
9
+ describe :kind do
10
+ it "must return class or type" do
11
+ subject.kind.must_equal :ICAO
12
+ end
13
+ end
14
+
15
+ describe :to_digest do
16
+ it "must return digest of payload" do
17
+ subject.to_digest.must_equal 582056647
18
+ end
19
+ end
20
+
21
+ describe :to_xml do
22
+ it "must build correct XML of VOR with OFM extension" do
23
+ subject.to_xml(:ofm).must_equal <<~END
24
+ <!-- Navigational aid: [ICAO] DESIGNATED POINT NAVAID -->
25
+ <Dpn>
26
+ <DpnUid newEntity="true">
27
+ <codeId>DPN</codeId>
28
+ <geoLat>47.85916667N</geoLat>
29
+ <geoLong>7.56000000E</geoLong>
30
+ </DpnUid>
31
+ <OrgUid/>
32
+ <txtName>DESIGNATED POINT NAVAID</txtName>
33
+ <codeDatum>WGE</codeDatum>
34
+ <codeType>ICAO</codeType>
35
+ <valElev>500</valElev>
36
+ <uomDistVer>FT</uomDistVer>
37
+ <txtRmk>designated point navaid</txtRmk>
38
+ </Dpn>
39
+ END
40
+ end
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,43 @@
1
+ require_relative '../../../../spec_helper'
2
+
3
+ describe AIXM::Feature::NavigationalAid::DME do
4
+ context "complete" do
5
+ subject do
6
+ AIXM::Factory.dme
7
+ end
8
+
9
+ describe :kind do
10
+ it "must return class or type" do
11
+ subject.kind.must_equal :DME
12
+ end
13
+ end
14
+
15
+ describe :to_digest do
16
+ it "must return digest of payload" do
17
+ subject.to_digest.must_equal 30256638
18
+ end
19
+ end
20
+
21
+ describe :to_xml do
22
+ it "must build correct XML with OFM extension" do
23
+ subject.to_xml(:ofm).must_equal <<~END
24
+ <!-- Navigational aid: [DME] DME NAVAID -->
25
+ <Dme>
26
+ <DmeUid newEntity="true">
27
+ <codeId>DME</codeId>
28
+ <geoLat>47.85916667N</geoLat>
29
+ <geoLong>7.56000000E</geoLong>
30
+ </DmeUid>
31
+ <OrgUid/>
32
+ <txtName>DME NAVAID</txtName>
33
+ <codeChannel>95X</codeChannel>
34
+ <codeDatum>WGE</codeDatum>
35
+ <valElev>500</valElev>
36
+ <uomDistVer>FT</uomDistVer>
37
+ <txtRmk>dme navaid</txtRmk>
38
+ </Dme>
39
+ END
40
+ end
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,44 @@
1
+ require_relative '../../../../spec_helper'
2
+
3
+ describe AIXM::Feature::NavigationalAid::Marker do
4
+ context "complete" do
5
+ subject do
6
+ AIXM::Factory.marker
7
+ end
8
+
9
+ describe :kind do
10
+ it "must return class or type" do
11
+ subject.kind.must_equal :Marker
12
+ end
13
+ end
14
+
15
+ describe :to_digest do
16
+ it "must return digest of payload" do
17
+ subject.to_digest.must_equal 371155747
18
+ end
19
+ end
20
+
21
+ describe :to_xml do
22
+ it "must build correct XML with OFM extension" do
23
+ subject.to_xml(:ofm).must_equal <<~END
24
+ <!-- Navigational aid: [Marker] MARKER NAVAID -->
25
+ <Mkr>
26
+ <MkrUid newEntity="true">
27
+ <codeId>---</codeId>
28
+ <geoLat>47.85916667N</geoLat>
29
+ <geoLong>7.56000000E</geoLong>
30
+ </MkrUid>
31
+ <OrgUid/>
32
+ <valFreq>75</valFreq>
33
+ <uomFreq>MHZ</uomFreq>
34
+ <txtName>MARKER NAVAID</txtName>
35
+ <codeDatum>WGE</codeDatum>
36
+ <valElev>500</valElev>
37
+ <uomDistVer>FT</uomDistVer>
38
+ <txtRmk>marker navaid</txtRmk>
39
+ </Mkr>
40
+ END
41
+ end
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,54 @@
1
+ require_relative '../../../../spec_helper'
2
+
3
+ describe AIXM::Feature::NavigationalAid::NDB do
4
+ describe :initialize do
5
+ let :f do
6
+ AIXM.f(555, :khz)
7
+ end
8
+
9
+ it "won't accept invalid arguments" do
10
+ -> { AIXM.ndb(id: 'N', name: 'NDB', xy: AIXM::Factory.xy, f: 0) }.must_raise ArgumentError
11
+ end
12
+ end
13
+
14
+ context "complete" do
15
+ subject do
16
+ AIXM::Factory.ndb
17
+ end
18
+
19
+ describe :kind do
20
+ it "must return class or type" do
21
+ subject.kind.must_equal :NDB
22
+ end
23
+ end
24
+
25
+ describe :to_digest do
26
+ it "must return digest of payload" do
27
+ subject.to_digest.must_equal 839752023
28
+ end
29
+ end
30
+
31
+ describe :to_xml do
32
+ it "must build correct XML with OFM extension" do
33
+ subject.to_xml(:ofm).must_equal <<~END
34
+ <!-- Navigational aid: [NDB] NDB NAVAID -->
35
+ <Ndb>
36
+ <NdbUid newEntity="true">
37
+ <codeId>NDB</codeId>
38
+ <geoLat>47.85916667N</geoLat>
39
+ <geoLong>7.56000000E</geoLong>
40
+ </NdbUid>
41
+ <OrgUid/>
42
+ <txtName>NDB NAVAID</txtName>
43
+ <valFreq>555</valFreq>
44
+ <uomFreq>KHZ</uomFreq>
45
+ <codeDatum>WGE</codeDatum>
46
+ <valElev>500</valElev>
47
+ <uomDistVer>FT</uomDistVer>
48
+ <txtRmk>ndb navaid</txtRmk>
49
+ </Ndb>
50
+ END
51
+ end
52
+ end
53
+ end
54
+ end
@@ -0,0 +1,43 @@
1
+ require_relative '../../../../spec_helper'
2
+
3
+ describe AIXM::Feature::NavigationalAid::TACAN do
4
+ context "complete" do
5
+ subject do
6
+ AIXM::Factory.tacan
7
+ end
8
+
9
+ describe :kind do
10
+ it "must return class or type" do
11
+ subject.kind.must_equal :TACAN
12
+ end
13
+ end
14
+
15
+ describe :to_digest do
16
+ it "must return digest of payload" do
17
+ subject.to_digest.must_equal 518546211
18
+ end
19
+ end
20
+
21
+ describe :to_xml do
22
+ it "must build correct XML with OFM extension" do
23
+ subject.to_xml(:ofm).must_equal <<~END
24
+ <!-- Navigational aid: [TACAN] TACAN NAVAID -->
25
+ <Tcn>
26
+ <TcnUid newEntity="true">
27
+ <codeId>TCN</codeId>
28
+ <geoLat>47.85916667N</geoLat>
29
+ <geoLong>7.56000000E</geoLong>
30
+ </TcnUid>
31
+ <OrgUid/>
32
+ <txtName>TACAN NAVAID</txtName>
33
+ <codeChannel>29X</codeChannel>
34
+ <codeDatum>WGE</codeDatum>
35
+ <valElev>500</valElev>
36
+ <uomDistVer>FT</uomDistVer>
37
+ <txtRmk>tacan navaid</txtRmk>
38
+ </Tcn>
39
+ END
40
+ end
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,58 @@
1
+ require_relative '../../../../spec_helper'
2
+
3
+ describe AIXM::Feature::NavigationalAid::VOR do
4
+ describe :initialize do
5
+ let :f do
6
+ AIXM.f(111, :mhz)
7
+ end
8
+
9
+ it "won't accept invalid arguments" do
10
+ -> { AIXM.vor(id: 'V', name: 'VOR', xy: AIXM::Factory.xy, type: :foo, f: f, north: :geographic) }.must_raise ArgumentError
11
+ -> { AIXM.vor(id: 'V', name: 'VOR', xy: AIXM::Factory.xy, type: :vor, f: 0, north: :geographic) }.must_raise ArgumentError
12
+ -> { AIXM.vor(id: 'V', name: 'VOR', xy: AIXM::Factory.xy, type: :vor, f: f, north: :foobar) }.must_raise ArgumentError
13
+ end
14
+ end
15
+
16
+ context "complete" do
17
+ subject do
18
+ AIXM::Factory.vor
19
+ end
20
+
21
+ describe :kind do
22
+ it "must return class or type" do
23
+ subject.kind.must_equal :VOR
24
+ end
25
+ end
26
+
27
+ describe :to_digest do
28
+ it "must return digest of payload" do
29
+ subject.to_digest.must_equal 276222546
30
+ end
31
+ end
32
+
33
+ describe :to_xml do
34
+ it "must build correct XML of VOR with OFM extension" do
35
+ subject.to_xml(:ofm).must_equal <<~END
36
+ <!-- Navigational aid: [VOR] VOR NAVAID -->
37
+ <Vor>
38
+ <VorUid newEntity="true">
39
+ <codeId>VOR</codeId>
40
+ <geoLat>47.85916667N</geoLat>
41
+ <geoLong>7.56000000E</geoLong>
42
+ </VorUid>
43
+ <OrgUid/>
44
+ <txtName>VOR NAVAID</txtName>
45
+ <codeType>VOR</codeType>
46
+ <valFreq>111</valFreq>
47
+ <uomFreq>MHZ</uomFreq>
48
+ <codeTypeNorth>TRUE</codeTypeNorth>
49
+ <codeDatum>WGE</codeDatum>
50
+ <valElev>500</valElev>
51
+ <uomDistVer>FT</uomDistVer>
52
+ <txtRmk>vor navaid</txtRmk>
53
+ </Vor>
54
+ END
55
+ end
56
+ end
57
+ end
58
+ end
@@ -41,6 +41,33 @@ describe AIXM::Refinements do
41
41
  end
42
42
  end
43
43
 
44
+ describe 'Hash#lookup' do
45
+ subject do
46
+ { one: 1, two: 2, three: 3, four: :three }
47
+ end
48
+
49
+ it "must return value for key if key is present" do
50
+ subject.lookup(:one).must_equal 1
51
+ end
52
+
53
+ it "must return value if key is not found but value is present" do
54
+ subject.lookup(1).must_equal 1
55
+ end
56
+
57
+ it "must return value for key if both key and value are present" do
58
+ subject.lookup(:three).must_equal 3
59
+ end
60
+
61
+ it "returns default if neither key nor value are present" do
62
+ subject.lookup(:foo, :default).must_equal :default
63
+ subject.lookup(:foo, nil).must_be_nil
64
+ end
65
+
66
+ it "fails if neither key, value nor default are present" do
67
+ -> { subject.lookup(:foo) }.must_raise KeyError
68
+ end
69
+ end
70
+
44
71
  describe 'String#indent' do
45
72
  it "must indent single line string" do
46
73
  'foobar'.indent(2).must_equal ' foobar'