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
# 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] = $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}")]) { |v| @options[:airac] = AIPP::AIRAC.new(v) }
    o.on('-r', '--region STRING', String, 'region (e.g. "LF")') { |v| @options[:region] = v.upcase }
    o.on('-a', '--aip STRING', String, 'process this AIP only (e.g. "ENR-5.1")') { |v| @options[:aip] = v.upcase }
    o.on('-s', '--storage DIR', String, 'storage directory (default: "~/.aipp")') { |v| @options[:storage] = Pathname(v) }
    o.on('-f', '--[no-]force', 'ignore XML schema validation (default: false)') { |v| @options[:force] = v }
    o.on('-v', '--[no-]verbose', 'verbose output (default: false)') { |v| $VERBOSE_INFO = v }
    o.on('-w', '--pry-on-warn [ID]', Integer, 'open pry on warn with ID (default: nil)') { |v| $PRY_ON_WARN = v || true }
    o.on('-e', '--[no-]pry-on-error', 'open pry on error (default: false)') { |v| $PRY_ON_ERROR = v }
    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



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/aipp/executable.rb', line 35

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_aixm
      parser.write_config
    end
  rescue => error
    puts "ERROR: #{error.message}"
    Pry::rescued(error) if $PRY_ON_ERROR
  end
end