aixm 0.1.0 → 0.1.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.
Files changed (40) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +29 -1
  3. data/Guardfile +1 -1
  4. data/README.md +146 -17
  5. data/aixm.gemspec +3 -1
  6. data/lib/aixm.rb +12 -10
  7. data/lib/aixm/component/base.rb +6 -0
  8. data/lib/aixm/component/class_layer.rb +49 -0
  9. data/lib/aixm/component/geometry.rb +73 -0
  10. data/lib/aixm/component/geometry/arc.rb +53 -0
  11. data/lib/aixm/component/geometry/border.rb +49 -0
  12. data/lib/aixm/component/geometry/circle.rb +56 -0
  13. data/lib/aixm/component/geometry/point.rb +42 -0
  14. data/lib/aixm/component/schedule.rb +45 -0
  15. data/lib/aixm/{vertical/limits.rb → component/vertical_limits.rb} +9 -14
  16. data/lib/aixm/document.rb +30 -19
  17. data/lib/aixm/feature/airspace.rb +60 -29
  18. data/lib/aixm/refinements.rb +49 -2
  19. data/lib/aixm/shortcuts.rb +30 -0
  20. data/lib/aixm/version.rb +1 -1
  21. data/spec/factory.rb +42 -25
  22. data/spec/lib/aixm/component/class_layer_spec.rb +74 -0
  23. data/spec/lib/aixm/{horizontal → component/geometry}/arc_spec.rb +11 -11
  24. data/spec/lib/aixm/component/geometry/border_spec.rb +30 -0
  25. data/spec/lib/aixm/{horizontal → component/geometry}/circle_spec.rb +8 -8
  26. data/spec/lib/aixm/{horizontal → component/geometry}/point_spec.rb +7 -7
  27. data/spec/lib/aixm/{geometry_spec.rb → component/geometry_spec.rb} +39 -40
  28. data/spec/lib/aixm/component/schedule_spec.rb +33 -0
  29. data/spec/lib/aixm/{vertical/limits_spec.rb → component/vertical_limits_spec.rb} +10 -10
  30. data/spec/lib/aixm/document_spec.rb +97 -36
  31. data/spec/lib/aixm/feature/airspace_spec.rb +230 -71
  32. data/spec/lib/aixm/refinements_spec.rb +52 -12
  33. metadata +30 -23
  34. data/lib/aixm/constants.rb +0 -6
  35. data/lib/aixm/geometry.rb +0 -71
  36. data/lib/aixm/horizontal/arc.rb +0 -50
  37. data/lib/aixm/horizontal/border.rb +0 -45
  38. data/lib/aixm/horizontal/circle.rb +0 -53
  39. data/lib/aixm/horizontal/point.rb +0 -39
  40. data/spec/lib/aixm/horizontal/border_spec.rb +0 -47
@@ -1,6 +0,0 @@
1
- module AIXM
2
-
3
- SCHEMA = Pathname(__dir__).join('schemas', '4.5', 'AIXM-Snapshot.xsd').freeze
4
- GROUND = AIXM::Z.new(alt: 0, code: :QFE).freeze
5
-
6
- end
@@ -1,71 +0,0 @@
1
- module AIXM
2
- class Geometry
3
-
4
- include Enumerable
5
- extend Forwardable
6
- using AIXM::Refinements
7
-
8
- def_delegators :@result_array, :each, :<<
9
-
10
- ##
11
- # Define a shape (horizontal geometry) which is either exactly one
12
- # +AIXM::Horizontals::Circle+ or any number of +AIXM::Horizontals::Point+,
13
- # +::Arc+ and +::Border+.
14
- #
15
- # Example 1:
16
- # geometry = AIXM::Geometry.new(
17
- # AIXM::Horizontals::Point(...),
18
- # AIXM::Horizontals::Point(...)
19
- # )
20
- #
21
- # Example 2:
22
- # geometry = AIXM::Geometry.new
23
- # geometry << AIXM::Horizontals::Point(...)
24
- # geometry << AIXM::Horizontals::Point(...)
25
- def initialize(*horizontals)
26
- @result_array = horizontals
27
- end
28
-
29
- ##
30
- # Array of +AIXM::Horizontal::...+ objects
31
- def horizontals
32
- @result_array
33
- end
34
-
35
- ##
36
- # Check whether the geometry is valid
37
- def valid?
38
- circle? || closed_shape?
39
- end
40
-
41
- ##
42
- # Digest to identify the payload
43
- def to_digest
44
- horizontals.map(&:to_digest).to_digest
45
- end
46
-
47
- ##
48
- # Render AIXM
49
- #
50
- # Extensions:
51
- # * +:OFM+ - Open Flightmaps
52
- def to_xml(*extensions)
53
- @result_array.map { |h| h.to_xml(extensions) }.join
54
- end
55
-
56
- private
57
-
58
- def circle?
59
- @result_array.size == 1 &&
60
- @result_array.first.is_a?(AIXM::Horizontal::Circle)
61
- end
62
-
63
- def closed_shape?
64
- @result_array.size >= 3 &&
65
- !@result_array.any? { |h| h.is_a?(AIXM::Horizontal::Circle) } &&
66
- @result_array.last.is_a?(AIXM::Horizontal::Point) &&
67
- @result_array.first.xy == @result_array.last.xy
68
- end
69
-
70
- end
71
- end
@@ -1,50 +0,0 @@
1
- module AIXM
2
- module Horizontal
3
- class Arc < Point
4
-
5
- using AIXM::Refinements
6
-
7
- attr_reader :center_xy
8
-
9
- ##
10
- # Defines a +clockwise+ (true/false) arc around +center_xy+ and starting
11
- # at +xy+
12
- def initialize(xy:, center_xy:, clockwise:)
13
- super(xy: xy)
14
- fail(ArgumentError, "invalid center xy") unless center_xy.is_a? AIXM::XY
15
- fail(ArgumentError, "clockwise must be true or false") unless [true, false].include? clockwise
16
- @center_xy, @clockwise = center_xy, clockwise
17
- end
18
-
19
- ##
20
- # Whether the arc is going clockwise (true) or not (false)
21
- def clockwise?
22
- @clockwise
23
- end
24
-
25
- ##
26
- # Digest to identify the payload
27
- def to_digest
28
- [xy.lat, xy.long, center_xy.lat, center_xy.long, clockwise?].to_digest
29
- end
30
-
31
- ##
32
- # Render AIXM
33
- #
34
- # Extensions:
35
- # * +:OFM+ - Open Flightmaps
36
- def to_xml(*extensions)
37
- builder = Builder::XmlMarkup.new(indent: 2)
38
- builder.Avx do |avx|
39
- avx.codeType(clockwise? ? 'CWA' : 'CCA')
40
- avx.geoLat(xy.lat(:AIXM))
41
- avx.geoLong(xy.long(:AIXM))
42
- avx.codeDatum('WGE')
43
- avx.geoLatArc(center_xy.lat(:AIXM))
44
- avx.geoLongArc(center_xy.long(:AIXM))
45
- end
46
- end
47
-
48
- end
49
- end
50
- end
@@ -1,45 +0,0 @@
1
- module AIXM
2
- module Horizontal
3
- class Border < Point
4
-
5
- using AIXM::Refinements
6
-
7
- attr_reader :name, :name_mid
8
-
9
- ##
10
- # Defines a (border) transition +name+/+mid+ starting at +xy+
11
- def initialize(xy:, name:, name_mid: nil)
12
- super(xy: xy)
13
- @name_mid, @name = name_mid, name
14
- end
15
-
16
- ##
17
- # Digest to identify the payload
18
- def to_digest
19
- [xy.lat, xy.long, name, name_mid].to_digest
20
- end
21
-
22
- ##
23
- # Render AIXM
24
- #
25
- # Extensions:
26
- # * +:OFM+ - Open Flightmaps
27
- def to_xml(*extensions)
28
- builder = Builder::XmlMarkup.new(indent: 2)
29
- builder.Avx do |avx|
30
- avx.codeType('FNT')
31
- avx.geoLat(xy.lat(:AIXM))
32
- avx.geoLong(xy.long(:AIXM))
33
- avx.codeDatum('WGE')
34
- # TODO: Find examples how to do this with vanilla AIXM
35
- if extensions.include?(:OFM)
36
- avx.GbrUid({ mid: name_mid }.compact) do |gbruid|
37
- gbruid.txtName('foobar')
38
- end
39
- end
40
- end
41
- end
42
-
43
- end
44
- end
45
- end
@@ -1,53 +0,0 @@
1
- module AIXM
2
- module Horizontal
3
- class Circle
4
-
5
- using AIXM::Refinements
6
-
7
- attr_reader :center_xy, :radius
8
-
9
- ##
10
- # Defines a circle around +center_xy+ with a +radius+ in kilometers
11
- def initialize(center_xy:, radius:)
12
- fail(ArgumentError, "invalid center xy") unless center_xy.is_a? AIXM::XY
13
- @center_xy, @radius = center_xy, radius
14
- end
15
-
16
- ##
17
- # Digest to identify the payload
18
- def to_digest
19
- [center_xy.lat, center_xy.long, radius].to_digest
20
- end
21
-
22
- ##
23
- # Render AIXM
24
- #
25
- # Extensions:
26
- # * +:OFM+ - Open Flightmaps
27
- def to_xml(*extensions)
28
- builder = Builder::XmlMarkup.new(indent: 2)
29
- builder.Avx do |avx|
30
- avx.codeType('CWA')
31
- avx.geoLat(north_xy.lat(:AIXM))
32
- avx.geoLong(north_xy.long(:AIXM))
33
- avx.codeDatum('WGE')
34
- avx.geoLatArc(center_xy.lat(:AIXM))
35
- avx.geoLongArc(center_xy.long(:AIXM))
36
- end
37
- end
38
-
39
- private
40
-
41
- ##
42
- # Coordinates of the point which is both strictly north of the center
43
- # and on the circumference of the circle
44
- def north_xy
45
- AIXM::XY.new(
46
- lat: center_xy.lat + radius.to_f / 6371 * 180 / Math::PI,
47
- long: center_xy.long
48
- )
49
- end
50
-
51
- end
52
- end
53
- end
@@ -1,39 +0,0 @@
1
- module AIXM
2
- module Horizontal
3
- class Point
4
-
5
- using AIXM::Refinements
6
-
7
- attr_reader :xy
8
-
9
- ##
10
- # Defines a point +xy+
11
- def initialize(xy:)
12
- fail(ArgumentError, "invalid xy") unless xy.is_a? AIXM::XY
13
- @xy = xy
14
- end
15
-
16
- ##
17
- # Digest to identify the payload
18
- def to_digest
19
- [xy.lat, xy.long].to_digest
20
- end
21
-
22
- ##
23
- # Render AIXM
24
- #
25
- # Extensions:
26
- # * +:OFM+ - Open Flightmaps
27
- def to_xml(*extensions)
28
- builder = Builder::XmlMarkup.new(indent: 2)
29
- builder.Avx do |avx|
30
- avx.codeType('GRC')
31
- avx.geoLat(xy.lat(:AIXM))
32
- avx.geoLong(xy.long(:AIXM))
33
- avx.codeDatum('WGE')
34
- end
35
- end
36
-
37
- end
38
- end
39
- end
@@ -1,47 +0,0 @@
1
- require_relative '../../../spec_helper'
2
-
3
- describe AIXM::Horizontal::Border do
4
- describe :to_digest do
5
- it "must return digest of payload" do
6
- subject = AIXM::Horizontal::Border.new(
7
- xy: AIXM::XY.new(lat: 11.1, long: 22.2),
8
- name: 'foobar',
9
- name_mid: 123
10
- )
11
- subject.to_digest.must_equal '8955450F'
12
- end
13
- end
14
-
15
- describe :to_xml do
16
- it "must build correct XML with name_mid" do
17
- subject = AIXM::Horizontal::Border.new(
18
- xy: AIXM::XY.new(lat: 11.1, long: 22.2),
19
- name: 'foobar',
20
- name_mid: 123
21
- )
22
- subject.to_xml.must_equal <<~END
23
- <Avx>
24
- <codeType>FNT</codeType>
25
- <geoLat>110600.00N</geoLat>
26
- <geoLong>0221200.00E</geoLong>
27
- <codeDatum>WGE</codeDatum>
28
- </Avx>
29
- END
30
- end
31
-
32
- it "must build correct XML without name_mid" do
33
- subject = AIXM::Horizontal::Border.new(
34
- xy: AIXM::XY.new(lat: 11.1, long: 22.2),
35
- name: 'foobar'
36
- )
37
- subject.to_xml.must_equal <<~END
38
- <Avx>
39
- <codeType>FNT</codeType>
40
- <geoLat>110600.00N</geoLat>
41
- <geoLong>0221200.00E</geoLong>
42
- <codeDatum>WGE</codeDatum>
43
- </Avx>
44
- END
45
- end
46
- end
47
- end