aipp 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 6636c547c07869e9f9e29ff7af681d2120b2010b870821066c773d06c464dd3e
4
+ data.tar.gz: 47c014f42d4934e516e9d6fa31c66c2cb53a5713786c899d0cc26872ea538963
5
+ SHA512:
6
+ metadata.gz: 69bebf7ef63cec882dce23b9072c5522e5de895b58308497105a0c0a042446cc099428cf7d40f01d811b8926a3d452cc3acdeb8573f4e1abb5e5b149dc50eb8e
7
+ data.tar.gz: 02b677a058bfd229d064452f22672814b079f9ccfa9bd8e210a0af81ce60fb6835a7d98d28a40a0b4905329e2edfcb3b055e70626b5411ec660837a45a76376c
data/.gitignore ADDED
@@ -0,0 +1,6 @@
1
+ .DS_Store
2
+ Gemfile.lock
3
+ pkg/*
4
+ *.gem
5
+ .bundle
6
+ *.aixm
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ ruby-2.5.0
data/.travis.yml ADDED
@@ -0,0 +1,5 @@
1
+ ---
2
+ language: ruby
3
+ rvm:
4
+ - 2.5.0
5
+ before_install: gem install bundler -v 1.16.1
data/CHANGELOG.md ADDED
@@ -0,0 +1,4 @@
1
+ ## 0.1.0
2
+
3
+ * Initial implementation of aip2aixm executable and infrastructure
4
+ * LF/ENR-5.1
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
data/Guardfile ADDED
@@ -0,0 +1,7 @@
1
+ clearing :on
2
+
3
+ guard :minitest do
4
+ watch(%r{^spec/(.+)_spec\.rb})
5
+ watch(%r{^lib/(.+)\.rb}) { |m| "spec/lib/#{m[1]}_spec.rb" }
6
+ watch(%r{^spec/spec_helper\.rb}) { 'spec' }
7
+ end
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Sven Schwyn
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,93 @@
1
+ [![Version](https://img.shields.io/gem/v/aipp.svg?style=flat)](https://rubygems.org/gems/aipp)
2
+ [![Continuous Integration](https://img.shields.io/travis/svoop/aipp/master.svg?style=flat)](https://travis-ci.org/svoop/aipp)
3
+ [![Code Climate](https://img.shields.io/codeclimate/github/svoop/aipp.svg?style=flat)](https://codeclimate.com/github/svoop/aipp)
4
+ [![Gitter](https://img.shields.io/gitter/room/svoop/aipp.svg?style=flat)](https://gitter.im/svoop/aipp)
5
+ [![Donorbox](https://img.shields.io/badge/donate-on_donorbox-yellow.svg)](https://donorbox.org/bitcetera)
6
+
7
+ # AIPP
8
+
9
+ Parser for Aeronautical Information Publication (AIP) available online.
10
+
11
+ This gem incluces an executable to download and parse aeronautical data, then
12
+ export is as [AIXM](https://github.com/svoop/aixm) which can be consumed by
13
+ [Open Flightmaps](https://openflightmaps.org).
14
+
15
+ * [Homepage](https://github.com/svoop/aipp)
16
+ * Author: [Sven Schwyn - Bitcetera](http://www.bitcetera.com)
17
+
18
+ ## Install
19
+
20
+ Add this to your <tt>Gemfile</tt>:
21
+
22
+ ```ruby
23
+ gem aipp
24
+ ```
25
+
26
+ ## Usage
27
+
28
+ ```
29
+ aip2aixm --help
30
+ ```
31
+
32
+ ## Parsers
33
+
34
+ Parsers are defined as modules and named +lib/aipp/parser/{FIR}/{AIP}.rb+. For
35
+ them to plug in, you have to define the following public methods:
36
+
37
+ * `url`<br>Must return the download URL of the AIP HTML as a string.
38
+ * `convert!`<br>Takes `html` ([Nokogiri document](https://github.com/sparklemotion/nokogiri)) to parse and populate `aixm` ([AIXM document](https://github.com/svoop/aixm))
39
+
40
+ You should read and honor the following attributes passed in from `aip2aixm`
41
+ arguments:
42
+
43
+ * `@fir`
44
+ * `@aip`
45
+ * `@airac`
46
+ * `@limit`
47
+
48
+ You should `fail` on fatal and `warn` on non-fatal problems. If `$DEBUG` is
49
+ +true+ (e.g. by use of the `-D` option), a Pry session will open if you use
50
+ `warn` as follows:
51
+
52
+ ```ruby
53
+ warn("my message", binding)
54
+ ```
55
+
56
+ ## AIRAC date calculations
57
+
58
+ ```ruby
59
+ airac = AIPP::AIRAC.new(Date.parse('2017-12-24'))
60
+ airac.date # => 2018-12-07
61
+ airac.id # => 1713
62
+ airac.next_date # => 2018-01-04
63
+ airac.next_id # => 1801
64
+ ```
65
+
66
+ ## References
67
+
68
+ * AIP authorities
69
+ * [LF: SIA](https://www.sia.aviation-civile.gouv.fr)
70
+ * [Open Flightmaps](https://openflightmaps.org)
71
+
72
+ ## Development
73
+
74
+ To install the development dependencies and then run the test suite:
75
+
76
+ ```
77
+ bundle install
78
+ bundle exec rake # run tests once
79
+ bundle exec guard # run tests whenever files are modified
80
+ ```
81
+
82
+ Please submit issues on:
83
+
84
+ https://github.com/svoop/aipp/issues
85
+
86
+ To contribute code, fork the project on Github, add your code and submit a
87
+ pull request:
88
+
89
+ https://help.github.com/articles/fork-a-repo
90
+
91
+ ## License
92
+
93
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,12 @@
1
+ require 'bundler/gem_tasks'
2
+
3
+ require 'rake/testtask'
4
+
5
+ Rake::TestTask.new do |t|
6
+ t.libs << 'lib'
7
+ t.test_files = FileList['spec/lib/**/*_spec.rb']
8
+ t.verbose = false
9
+ t.warning = true
10
+ end
11
+
12
+ task default: :test
data/aipp.gemspec ADDED
@@ -0,0 +1,37 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'aipp/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'aipp'
8
+ spec.version = AIPP::VERSION
9
+ spec.authors = ['Sven Schwyn']
10
+ spec.email = ['ruby@bitcetera.com']
11
+ spec.description = %q(Parser for Aeronautical Information Publications (AIP).)
12
+ spec.summary = %q(Parser for Aeronautical Information Publications (AIP).)
13
+ spec.homepage = 'https://github.com/svoop/aipp'
14
+ spec.license = 'MIT'
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.bindir = 'exe'
18
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
19
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
20
+ spec.require_paths = ['lib']
21
+
22
+ spec.required_ruby_version = '>= 2.5'
23
+
24
+ spec.add_development_dependency 'bundler'
25
+ spec.add_development_dependency 'rake'
26
+ spec.add_development_dependency 'minitest'
27
+ spec.add_development_dependency 'minitest-reporters'
28
+ spec.add_development_dependency 'minitest-sound'
29
+ spec.add_development_dependency 'minitest-matchers'
30
+ spec.add_development_dependency 'guard'
31
+ spec.add_development_dependency 'guard-minitest'
32
+
33
+ spec.add_runtime_dependency 'aixm', '~> 0', '>= 0.2.0'
34
+ spec.add_runtime_dependency 'nokogiri', '~> 1'
35
+ spec.add_runtime_dependency 'nokogumbo', '~> 1'
36
+ spec.add_runtime_dependency 'pry', '~> 0'
37
+ end
data/exe/aip2aixm ADDED
@@ -0,0 +1,60 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'bundler/inline'
4
+ require 'optparse'
5
+ require 'yaml'
6
+
7
+ gemfile do
8
+ source 'https://rubygems.org'
9
+ ruby '>= 2.5'
10
+ gem 'aipp', '~> 0'
11
+ end
12
+
13
+ class Executable
14
+ attr_reader :fir, :aip, :airac, :ofm, :limit, :verbose
15
+
16
+ def initialize
17
+ @ogn = false
18
+ @airac = AIPP::AIRAC.new(Date.today).date
19
+ @limit = Float::INFINITY
20
+ @verbose = false
21
+ OptionParser.new do |o|
22
+ o.banner = <<~END
23
+ Download online AIP and convert it to AIXM.
24
+ Usage: #{File.basename($0)} [options]
25
+ END
26
+ o.on('-A', '--about', 'author and license information') { puts 'Written by Sven Schwyn (bitcetera.com) and distributed under MIT license.'; exit }
27
+ o.on('-l', '--list', "list available FIR/AIP and exit") { puts AIPP::Loader.list.to_yaml; exit }
28
+ o.on('-f', '--fir STRING', String, 'FIR (flight information region, e.g. "LF")') { |v| @fir = v }
29
+ o.on('-a', '--aip STRING', String, 'AIP (aeronautical information publication, e.g. "ENR-5.1")') { |v| @aip = v }
30
+ o.on('-d', '--airac DATE', String, 'AIRAC date (e.g. "2018-01-04", default: current)') { |v| @airac = v }
31
+ o.on('-o', '--[no-]ofm', 'Use OFM extensions (default: false)') { |v| @ofm = v }
32
+ o.on('-L', '--limit INTEGER', Integer, 'Stop conversion after this many features') { |v| @limit = v }
33
+ o.on('-D', '--[no-]debug', 'Enable debug mode (default: false)') { |v| $DEBUG = v }
34
+ o.on('-v', '--[no-]verbose', 'Verbose error reporting (default: false)') { |v| @verbose = v }
35
+ end.parse!
36
+ fail(ArgumentError, "FIR must be supplied") unless @fir
37
+ fail(ArgumentError, "AIP must be supplied") unless @aip
38
+ fail(ArgumentError, "AIRAC date must be supplied") unless @airac
39
+ end
40
+
41
+ def run
42
+ extensions = [(:ofm if ofm)].compact
43
+ filename = [fir, aip, airac].join('_') + '.aixm'
44
+ loader = AIPP::Loader.new(fir: fir, aip: aip, airac: airac, limit: limit)
45
+ aixm = loader.aixm.to_xml(*extensions)
46
+ File.write(Pathname.new(Dir.pwd).join(filename), aixm)
47
+ end
48
+ end
49
+
50
+ begin
51
+ executable = Executable.new
52
+ executable.run
53
+ rescue => exception
54
+ if executable.verbose
55
+ raise exception
56
+ else
57
+ puts "#{File.basename($0)}: #{exception.message}"
58
+ exit 1
59
+ end
60
+ end
data/lib/aipp/airac.rb ADDED
@@ -0,0 +1,47 @@
1
+ module AIPP
2
+
3
+ ##
4
+ # Calculate the AIRAC date and AIRAC ID for the given +any_date+
5
+ class AIRAC
6
+ ##
7
+ # First AIRAC date following the last cycle length modification
8
+ ROOT_DATE = Date.parse('2015-06-25').freeze
9
+
10
+ ##
11
+ # Length of one AIRAC cycle
12
+ DAYS_PER_CYCLE = 28
13
+
14
+ attr_reader :date, :id
15
+
16
+ def initialize(any_date = nil)
17
+ any_date ||= Date.today
18
+ fail(ArgumentError, "argument must be of class Date") unless any_date.is_a? Date
19
+ fail(ArgumentError, "cannot calculate dates before #{ROOT_DATE}") if any_date < ROOT_DATE
20
+ @date = date_for(any_date)
21
+ @id = id_for(@date)
22
+ end
23
+
24
+ def next_date
25
+ date + DAYS_PER_CYCLE
26
+ end
27
+
28
+ def next_id
29
+ id_for next_date
30
+ end
31
+
32
+ private
33
+
34
+ ##
35
+ # Find the AIRAC date for +any_date+
36
+ def date_for(any_date)
37
+ ROOT_DATE + (any_date - ROOT_DATE).to_i / DAYS_PER_CYCLE * DAYS_PER_CYCLE
38
+ end
39
+
40
+ ##
41
+ # Find the AIRAC ID for the AIRAC +date+
42
+ def id_for(date)
43
+ (date.year % 100) * 100 + ((date.yday - 1) / 28) + 1
44
+ end
45
+
46
+ end
47
+ end
@@ -0,0 +1,42 @@
1
+ module AIPP
2
+ class Loader
3
+ using AIPP::Refinements
4
+
5
+ attr_accessor :aixm
6
+
7
+ def self.list
8
+ parser_path = Pathname(__dir__).join('parser')
9
+ Dir.each_child(parser_path).each.with_object({}) do |fir, hash|
10
+ hash[fir] = Dir.children(parser_path.join(fir)).map do |aip_file|
11
+ File.basename(aip_file, '.rb')
12
+ end
13
+ end
14
+ end
15
+
16
+ def initialize(fir:, aip:, airac:, limit:)
17
+ @fir, @aip, @airac, @limit = fir.upcase, aip.upcase, airac, limit
18
+ require_relative "parser/#{@fir}/#{@aip}.rb"
19
+ self.singleton_class.send(:include, AIPP::Parser)
20
+ @aixm = AIXM.document(effective_at: @airac)
21
+ convert!
22
+ warn "WARNING: document is not complete" unless aixm.complete?
23
+ warn aixm.errors.prepend("WARNING: document ist not valid:").join("\n") unless aixm.valid?
24
+ rescue LoadError
25
+ raise(LoadError, "no parser found for FIR `#{@fir}' and AIP `#{@aip}'")
26
+ end
27
+
28
+ private
29
+
30
+ def file
31
+ file_name = "#{@fir}_#{@aip}_#{@airac}.html"
32
+ Pathname.new(Dir.tmpdir).join(file_name).tap do |file_path|
33
+ IO.copy_stream(open(url), file_path) unless File.exist?(file_path)
34
+ end
35
+ end
36
+
37
+ def html
38
+ @html ||= Nokogiri::HTML5(file)
39
+ end
40
+
41
+ end
42
+ end
@@ -0,0 +1,140 @@
1
+ module AIPP
2
+ module Parser
3
+ using AIPP::Refinements
4
+ using AIXM::Refinements
5
+
6
+ TYPES = {
7
+ 'D' => :D,
8
+ 'P' => :P,
9
+ 'R' => :R,
10
+ 'ZIT' => :P
11
+ }.freeze
12
+
13
+ BORDERS = {
14
+ 'franco-allemande' => 'FRANCE_GERMANY',
15
+ 'franco-espagnole' => 'FRANCE_SPAIN',
16
+ 'franco-italienne' => 'FRANCE_ITALY',
17
+ 'franco-suisse' => 'FRANCE_SWITZERLAND',
18
+ 'franco-luxembourgeoise' => 'FRANCE_LUXEMBOURG',
19
+ 'franco-belge' => 'BELGIUM_FRANCE'
20
+ }.freeze
21
+
22
+ def url
23
+ "https://www.sia.aviation-civile.gouv.fr/dvd/eAIP_%s/FRANCE/AIRAC-%s/html/eAIP/FR-%s-fr-FR.html" % [
24
+ aixm.effective_at.strftime('%d_%^b_%Y'), # 04_JAN_2018
25
+ aixm.effective_at.to_date.xmlschema, # 2018-01-04
26
+ @aip # ENR-5.1
27
+ ]
28
+ end
29
+
30
+ def convert!
31
+ html.css('tbody:has(tr[id^=mid])').each do |tbody|
32
+ airspace = nil
33
+ tbody.css('tr').each_with_index do |tr, index|
34
+ if tr.attr(:class) =~ /keep-with-next-row/
35
+ airspace = airspace_from tr
36
+ else
37
+ begin
38
+ tds = tr.css('td')
39
+ airspace.geometry = geometry_from tds[0]
40
+ airspace.class_layers << class_layer_from(tds[1])
41
+ airspace.schedule = schedule_from tds[2]
42
+ airspace.remarks = remarks_from(tds[2], tds[3], tds[4])
43
+ fail "airspace `#{airspace.name}' is not complete" unless airspace.complete?
44
+ aixm.features << airspace
45
+ break if index / 2 > @limit
46
+ rescue => exception
47
+ warn("WARNING: error parsing airspace `#{airspace.name}': #{exception.message}", binding)
48
+ end
49
+ end
50
+ end
51
+ end
52
+ true
53
+ end
54
+
55
+ private
56
+
57
+ def airspace_from(tr)
58
+ spans = tr.css(:span)
59
+ AIXM.airspace(
60
+ name: [spans[1], spans[2], spans[3], spans[5].text.blank_to_nil].compact.join(' '),
61
+ short_name: [spans[1], spans[2], spans[3]].compact.join(' '),
62
+ type: TYPES.fetch(spans[2].text)
63
+ )
64
+ end
65
+
66
+ def geometry_from(td)
67
+ AIXM.geometry.tap do |geometry|
68
+ buffer = {}
69
+ td.text.gsub(/\s+/, ' ').strip.split(/ - /).append('end').each do |element|
70
+ case element
71
+ when /frontière (.+)/i
72
+ geometry << AIXM.border(
73
+ xy: buffer.delete(:xy),
74
+ name: BORDERS.fetch($1)
75
+ )
76
+ when /arc (anti-)?horaire .+ sur (\S+) , (\S+)/i
77
+ geometry << AIXM.arc(
78
+ xy: buffer.delete(:xy),
79
+ center_xy: AIXM.xy(lat: $2, long: $3),
80
+ clockwise: $1.nil?
81
+ )
82
+ when /cercle de ([\d\.]+) (NM|km|m) .+ sur (\S+) , (\S+)/i
83
+ geometry << AIXM.circle(
84
+ center_xy: AIXM.xy(lat: $3, long: $4),
85
+ radius: $1.to_f.to_km(from: $2).round(3)
86
+ )
87
+ when /end|(\S+) , (\S+)/
88
+ geometry << AIXM.point(xy: buffer[:xy]) if buffer.has_key?(:xy)
89
+ buffer[:xy] = AIXM.xy(lat: $1, long: $2) if $1
90
+ else
91
+ fail "geometry `#{element}' not recognized"
92
+ end
93
+ end
94
+ end
95
+ end
96
+
97
+ def class_layer_from(td)
98
+ above, below = td.text.gsub(/ /, '').split(/\n+/).select(&:blank_to_nil).split(/---+/)
99
+ above.reverse!
100
+ AIXM.class_layer(
101
+ vertical_limits: AIXM.vertical_limits(
102
+ max_z: z_from(above[1]),
103
+ upper_z: z_from(above[0]),
104
+ lower_z: z_from(below[0]),
105
+ min_z: z_from(below[1])
106
+ )
107
+ )
108
+ end
109
+
110
+ def z_from(limit)
111
+ case limit
112
+ when nil then nil
113
+ when 'SFC' then AIXM::GROUND
114
+ when 'UNL' then AIXM::UNLIMITED
115
+ when /(\d+)ftASFC/ then AIXM.z($1.to_i, :qfe)
116
+ when /(\d+)ftAMSL/ then AIXM.z($1.to_i, :qnh)
117
+ when /FL(\d+)/ then AIXM.z($1.to_i, :qne)
118
+ else fail "z `#{limit}' not recognized"
119
+ end
120
+ end
121
+
122
+ def schedule_from(td)
123
+ AIXM::H24 if td.text.gsub(/\W/, '') == 'H24'
124
+ end
125
+
126
+ def remarks_from(*parts)
127
+ part_titles = ['SCHEDULE', 'RESTRICTION', 'AUTHORITY/CONDITIONS']
128
+ [].tap do |remarks|
129
+ parts.each.with_index do |part, index|
130
+ if part = part.text.gsub(/ +/, ' ').gsub(/(\n ?)+/, "\n").strip.blank_to_nil
131
+ unless index.zero? && part == 'H24'
132
+ remarks << "#{part_titles[index]}:\n#{part}"
133
+ end
134
+ end
135
+ end
136
+ end.join("\n\n")
137
+ end
138
+
139
+ end
140
+ end
@@ -0,0 +1,51 @@
1
+ module AIPP
2
+ module Refinements
3
+
4
+ refine Kernel do
5
+ def warn(message, binding=nil)
6
+ super(message)
7
+ if $DEBUG && binding
8
+ require 'pry'
9
+ binding.pry
10
+ end
11
+ end
12
+ end
13
+
14
+ refine String do
15
+ ##
16
+ # Convert blank strings to +nil+
17
+ def blank_to_nil
18
+ match?(/\A\s*\z/) ? nil : self
19
+ end
20
+ end
21
+
22
+ refine NilClass do
23
+ ##
24
+ # Companion to String#blank_to_nil
25
+ def blank_to_nil
26
+ self
27
+ end
28
+ end
29
+
30
+ refine Array do
31
+ ##
32
+ # Split an array into nested arrays at the pattern (similar to +String#split+)
33
+ def split(pattern)
34
+ [].tap do |array|
35
+ nested_array = []
36
+ each do |element|
37
+ if pattern === element
38
+ array << nested_array
39
+ nested_array = []
40
+ else
41
+ nested_array << element
42
+ end
43
+ end
44
+ array << nested_array
45
+ array.pop while array.last == []
46
+ end
47
+ end
48
+ end
49
+
50
+ end
51
+ end
@@ -0,0 +1,3 @@
1
+ module AIPP
2
+ VERSION = "0.1.0".freeze
3
+ end
data/lib/aipp.rb ADDED
@@ -0,0 +1,12 @@
1
+ require 'tmpdir'
2
+ require 'pathname'
3
+ require 'open-uri'
4
+ require 'date'
5
+ require 'nokogiri'
6
+ require 'nokogumbo'
7
+ require 'aixm'
8
+
9
+ require_relative 'aipp/version'
10
+ require_relative 'aipp/airac'
11
+ require_relative 'aipp/refinements'
12
+ require_relative 'aipp/loader'
@@ -0,0 +1,98 @@
1
+ require_relative '../../spec_helper'
2
+
3
+ describe AIPP::AIRAC do
4
+ describe :initialize do
5
+ it "won't accept invalid arguments" do
6
+ -> { AIPP::AIRAC.new(0) }.must_raise ArgumentError
7
+ -> { AIPP::AIRAC.new(AIPP::AIRAC::ROOT_DATE - 1) }.must_raise ArgumentError
8
+ end
9
+ end
10
+
11
+ context "on AIRAC date" do
12
+ subject do
13
+ AIPP::AIRAC.new(Date.parse('2018-01-04'))
14
+ end
15
+
16
+ it "must calculate correct #date" do
17
+ subject.date.must_equal Date.parse('2018-01-04')
18
+ end
19
+
20
+ it "must calculate correct #id" do
21
+ subject.id.must_equal 1801
22
+ end
23
+
24
+ it "must calculate correct #next_date" do
25
+ subject.next_date.must_equal Date.parse('2018-02-01')
26
+ end
27
+
28
+ it "must calculate correct #next_id" do
29
+ subject.next_id.must_equal 1802
30
+ end
31
+ end
32
+
33
+ context "one day before AIRAC date" do
34
+ subject do
35
+ AIPP::AIRAC.new(Date.parse('2018-01-03'))
36
+ end
37
+
38
+ it "must calculate correct #date" do
39
+ subject.date.must_equal Date.parse('2017-12-07')
40
+ end
41
+
42
+ it "must calculate correct #id" do
43
+ subject.id.must_equal 1713
44
+ end
45
+
46
+ it "must calculate correct #next_date" do
47
+ subject.next_date.must_equal Date.parse('2018-01-04')
48
+ end
49
+
50
+ it "must calculate correct #next_id" do
51
+ subject.next_id.must_equal 1801
52
+ end
53
+ end
54
+
55
+ context "one day after AIRAC date" do
56
+ subject do
57
+ AIPP::AIRAC.new(Date.parse('2018-01-05'))
58
+ end
59
+
60
+ it "must calculate correct #date" do
61
+ subject.date.must_equal Date.parse('2018-01-04')
62
+ end
63
+
64
+ it "must calculate correct #id" do
65
+ subject.id.must_equal 1801
66
+ end
67
+
68
+ it "must calculate correct #next_date" do
69
+ subject.next_date.must_equal Date.parse('2018-02-01')
70
+ end
71
+
72
+ it "must calculate correct #next_id" do
73
+ subject.next_id.must_equal 1802
74
+ end
75
+ end
76
+
77
+ context "end of year with 14 AIRAC cycles" do
78
+ subject do
79
+ AIPP::AIRAC.new(Date.parse('2020-12-31'))
80
+ end
81
+
82
+ it "must calculate correct #date" do
83
+ subject.date.must_equal Date.parse('2020-12-31')
84
+ end
85
+
86
+ it "must calculate correct #id" do
87
+ subject.id.must_equal 2014
88
+ end
89
+
90
+ it "must calculate correct #next_date" do
91
+ subject.next_date.must_equal Date.parse('2021-01-28')
92
+ end
93
+
94
+ it "must calculate correct #next_id" do
95
+ subject.next_id.must_equal 2101
96
+ end
97
+ end
98
+ end
@@ -0,0 +1,53 @@
1
+ require_relative '../../spec_helper'
2
+
3
+ using AIPP::Refinements
4
+
5
+ describe AIPP::Refinements do
6
+
7
+ describe 'String#blank_to_nil' do
8
+ it "must convert blank to nil" do
9
+ "\n \n ".blank_to_nil.must_be :nil?
10
+ end
11
+
12
+ it "must leave non-blank untouched" do
13
+ "foobar".blank_to_nil.must_equal "foobar"
14
+ end
15
+
16
+ it "must leave non-blank with whitespace untouched" do
17
+ "\nfoo bar\n".blank_to_nil.must_equal "\nfoo bar\n"
18
+ end
19
+ end
20
+
21
+ describe 'NilClass#blank_to_nil' do
22
+ it "must return self" do
23
+ nil.blank_to_nil.must_be :nil?
24
+ end
25
+ end
26
+
27
+ describe 'Array#split' do
28
+ it "must split at pattern" do
29
+ [1, 2, '---', 3, 4].split(/-+/).must_equal [[1, 2], [3, 4]]
30
+ end
31
+
32
+ it "won't split arrays with no pattern matches" do
33
+ [1, 2, 3].split(/-+/).must_equal [[1, 2, 3]]
34
+ end
35
+
36
+ it "must keep leading empty subarrays" do
37
+ ['---', 1, 2, '---', 3, 4].split(/-+/).must_equal [[], [1, 2], [3, 4]]
38
+ end
39
+
40
+ it "must keep empty subarrays in the middle" do
41
+ [1, 2, '---', '---', 3, 4].split(/-+/).must_equal [[1, 2], [], [3, 4]]
42
+ end
43
+
44
+ it "must drop trailing empty subarrays" do
45
+ [1, 2, '---', 3, 4, '---'].split(/-+/).must_equal [[1, 2], [3, 4]]
46
+ end
47
+
48
+ it "won't alter empty arrays" do
49
+ [].split(/-+/).must_equal []
50
+ end
51
+ end
52
+
53
+ end
@@ -0,0 +1,7 @@
1
+ require_relative '../../spec_helper'
2
+
3
+ describe AIPP do
4
+ it "must be defined" do
5
+ AIPP::VERSION.wont_be_nil
6
+ end
7
+ end
Binary file
Binary file
@@ -0,0 +1,27 @@
1
+ gem 'minitest'
2
+
3
+ require 'pathname'
4
+
5
+ require 'minitest/autorun'
6
+ require Pathname(__dir__).join('..', 'lib', 'aipp')
7
+
8
+ require 'minitest/sound'
9
+ require 'minitest/sound/reporter'
10
+ Minitest::Sound.success = Pathname(__dir__).join('sounds/success.mp3').to_s
11
+ Minitest::Sound.failure = Pathname(__dir__).join('sounds/failure.mp3').to_s
12
+ require 'minitest/reporters'
13
+ Minitest::Reporters.use! [Minitest::Reporters::SpecReporter.new, Minitest::Sound::Reporter.new]
14
+
15
+ require 'minitest/matchers'
16
+
17
+ module AIPP
18
+ def self.root
19
+ Pathname(__dir__).join('..')
20
+ end
21
+ end
22
+
23
+ class MiniTest::Spec
24
+ class << self
25
+ alias_method :context, :describe
26
+ end
27
+ end
metadata ADDED
@@ -0,0 +1,248 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: aipp
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Sven Schwyn
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2018-01-24 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: '0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
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
+ - !ruby/object:Gem::Dependency
42
+ name: minitest
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: minitest-reporters
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: minitest-sound
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: minitest-matchers
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: guard
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: guard-minitest
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ - !ruby/object:Gem::Dependency
126
+ name: aixm
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - "~>"
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ - - ">="
133
+ - !ruby/object:Gem::Version
134
+ version: 0.2.0
135
+ type: :runtime
136
+ prerelease: false
137
+ version_requirements: !ruby/object:Gem::Requirement
138
+ requirements:
139
+ - - "~>"
140
+ - !ruby/object:Gem::Version
141
+ version: '0'
142
+ - - ">="
143
+ - !ruby/object:Gem::Version
144
+ version: 0.2.0
145
+ - !ruby/object:Gem::Dependency
146
+ name: nokogiri
147
+ requirement: !ruby/object:Gem::Requirement
148
+ requirements:
149
+ - - "~>"
150
+ - !ruby/object:Gem::Version
151
+ version: '1'
152
+ type: :runtime
153
+ prerelease: false
154
+ version_requirements: !ruby/object:Gem::Requirement
155
+ requirements:
156
+ - - "~>"
157
+ - !ruby/object:Gem::Version
158
+ version: '1'
159
+ - !ruby/object:Gem::Dependency
160
+ name: nokogumbo
161
+ requirement: !ruby/object:Gem::Requirement
162
+ requirements:
163
+ - - "~>"
164
+ - !ruby/object:Gem::Version
165
+ version: '1'
166
+ type: :runtime
167
+ prerelease: false
168
+ version_requirements: !ruby/object:Gem::Requirement
169
+ requirements:
170
+ - - "~>"
171
+ - !ruby/object:Gem::Version
172
+ version: '1'
173
+ - !ruby/object:Gem::Dependency
174
+ name: pry
175
+ requirement: !ruby/object:Gem::Requirement
176
+ requirements:
177
+ - - "~>"
178
+ - !ruby/object:Gem::Version
179
+ version: '0'
180
+ type: :runtime
181
+ prerelease: false
182
+ version_requirements: !ruby/object:Gem::Requirement
183
+ requirements:
184
+ - - "~>"
185
+ - !ruby/object:Gem::Version
186
+ version: '0'
187
+ description: Parser for Aeronautical Information Publications (AIP).
188
+ email:
189
+ - ruby@bitcetera.com
190
+ executables:
191
+ - aip2aixm
192
+ extensions: []
193
+ extra_rdoc_files: []
194
+ files:
195
+ - ".gitignore"
196
+ - ".ruby-version"
197
+ - ".travis.yml"
198
+ - CHANGELOG.md
199
+ - Gemfile
200
+ - Guardfile
201
+ - LICENSE.txt
202
+ - README.md
203
+ - Rakefile
204
+ - aipp.gemspec
205
+ - exe/aip2aixm
206
+ - lib/aipp.rb
207
+ - lib/aipp/airac.rb
208
+ - lib/aipp/loader.rb
209
+ - lib/aipp/parser/LF/ENR-5.1.rb
210
+ - lib/aipp/refinements.rb
211
+ - lib/aipp/version.rb
212
+ - spec/lib/aipp/airac_spec.rb
213
+ - spec/lib/aipp/refinements_spec.rb
214
+ - spec/lib/aipp/version_spec.rb
215
+ - spec/sounds/failure.mp3
216
+ - spec/sounds/success.mp3
217
+ - spec/spec_helper.rb
218
+ homepage: https://github.com/svoop/aipp
219
+ licenses:
220
+ - MIT
221
+ metadata: {}
222
+ post_install_message:
223
+ rdoc_options: []
224
+ require_paths:
225
+ - lib
226
+ required_ruby_version: !ruby/object:Gem::Requirement
227
+ requirements:
228
+ - - ">="
229
+ - !ruby/object:Gem::Version
230
+ version: '2.5'
231
+ required_rubygems_version: !ruby/object:Gem::Requirement
232
+ requirements:
233
+ - - ">="
234
+ - !ruby/object:Gem::Version
235
+ version: '0'
236
+ requirements: []
237
+ rubyforge_project:
238
+ rubygems_version: 2.7.3
239
+ signing_key:
240
+ specification_version: 4
241
+ summary: Parser for Aeronautical Information Publications (AIP).
242
+ test_files:
243
+ - spec/lib/aipp/airac_spec.rb
244
+ - spec/lib/aipp/refinements_spec.rb
245
+ - spec/lib/aipp/version_spec.rb
246
+ - spec/sounds/failure.mp3
247
+ - spec/sounds/success.mp3
248
+ - spec/spec_helper.rb