Class: AIPP::Executable

Inherits:
Object show all
Defined in:
lib/aipp/executable.rb

Overview

Executable instantiated by the console tools

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(**options) ⇒ Executable

Returns a new instance of Executable.


7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/aipp/executable.rb', line 7

def initialize(**options)
  @options = options
  @options[:airac] = AIPP::AIRAC.new
  @options[:storage] = Pathname(Dir.home).join('.aipp')
  @options[:force] = @options[:mid] = false
  $VERBOSE_INFO = $PRY_ON_WARN = $PRY_ON_ERROR = false
  OptionParser.new do |o|
    o.banner = <<~END
      Download online AIP and convert it to #{options[:schema].upcase}.
      Usage: #{File.basename($0)} [options]
    END
    o.on('-d', '--airac DATE', String, %Q[AIRAC date (default: "#{@options[:airac].date.xmlschema}")]) { @options[:airac] = AIPP::AIRAC.new(_1) }
    o.on('-r', '--region STRING', String, 'region (e.g. "LF")') { @options[:region] = _1.upcase }
    o.on('-a', '--aip STRING', String, 'process this AIP only (e.g. "ENR-5.1")') { @options[:aip] = _1.upcase }
    if options[:schema] == :ofmx
      o.on('-g', '--[no-]grouped-obstacles', 'group obstacles (time-consuming!)') { @options[:grouped_obstacles] = _1 }
      o.on('-m', '--[no-]mid', 'insert mid attributes into all Uid elements (default: false)') { @options[:mid] = _1 }
    end
    o.on('-s', '--storage DIR', String, 'storage directory (default: "~/.aipp")') { @options[:storage] = Pathname(_1) }
    o.on('-f', '--[no-]force', 'ignore XML schema validation (default: false)') { @options[:force] = _1 }
    o.on('-v', '--[no-]verbose', 'verbose output (default: false)') { $VERBOSE_INFO = _1 }
    o.on('-w', '--pry-on-warn [ID]', Integer, 'open pry on warn with ID (default: nil)') { $PRY_ON_WARN = _1 || true }
    o.on('-e', '--[no-]pry-on-error', 'open pry on error (default: false)') { $PRY_ON_ERROR = _1 }
    o.on('-A', '--about', 'show author/license information and exit') { about }
    o.on('-R', '--readme', 'show README and exit') { readme }
    o.on('-L', '--list', 'list implemented regions and AIPs') { list }
    o.on('-V', '--version', 'show version and exit') { version }
  end.parse!
end

Instance Attribute Details

#optionsObject (readonly)

Returns the value of attribute options


5
6
7
# File 'lib/aipp/executable.rb', line 5

def options
  @options
end

Instance Method Details

#runObject

Load necessary files and execute the parser.

Raises:

  • (RuntimeError)

    if the region does not exist


40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/aipp/executable.rb', line 40

def run
  Pry.rescue do
    fail(OptionParser::MissingArgument, :region) unless options[:region]
    AIPP::Parser.new(options: options).tap do |parser|
      parser.read_config
      parser.read_region
      parser.parse_aip
      parser.validate_aixm
      parser.write_build
      parser.write_aixm
      parser.write_config
    end
  rescue => error
    puts "ERROR: #{error.message}".magenta
    Pry::rescued(error) if $PRY_ON_ERROR
  end
end