class AIPP::Executable
Executable
instantiated by the console tools
Attributes
options[R]
Public Class Methods
new(**options)
click to toggle source
# File lib/aipp/executable.rb 7 def initialize(**options) 8 @options = options 9 @options[:airac] = AIPP::AIRAC.new 10 @options[:storage] = Pathname(Dir.home).join('.aipp') 11 @options[:force] = @options[:mid] = false 12 $VERBOSE_INFO = $PRY_ON_WARN = $PRY_ON_ERROR = false 13 OptionParser.new do |o| 14 o.banner = <<~END 15 Download online AIP and convert it to #{options[:schema].upcase}. 16 Usage: #{File.basename($0)} [options] 17 END 18 o.on('-d', '--airac DATE', String, %Q[AIRAC date (default: "#{@options[:airac].date.xmlschema}")]) { @options[:airac] = AIPP::AIRAC.new(_1) } 19 o.on('-r', '--region STRING', String, 'region (e.g. "LF")') { @options[:region] = _1.upcase } 20 o.on('-a', '--aip STRING', String, 'process this AIP only (e.g. "ENR-5.1")') { @options[:aip] = _1.upcase } 21 if options[:schema] == :ofmx 22 o.on('-g', '--[no-]grouped-obstacles', 'group obstacles (time-consuming!)') { @options[:grouped_obstacles] = _1 } 23 o.on('-m', '--[no-]mid', 'insert mid attributes into all Uid elements (default: false)') { @options[:mid] = _1 } 24 end 25 o.on('-s', '--storage DIR', String, 'storage directory (default: "~/.aipp")') { @options[:storage] = Pathname(_1) } 26 o.on('-f', '--[no-]force', 'ignore XML schema validation (default: false)') { @options[:force] = _1 } 27 o.on('-v', '--[no-]verbose', 'verbose output (default: false)') { $VERBOSE_INFO = _1 } 28 o.on('-w', '--pry-on-warn [ID]', Integer, 'open pry on warn with ID (default: nil)') { $PRY_ON_WARN = _1 || true } 29 o.on('-e', '--[no-]pry-on-error', 'open pry on error (default: false)') { $PRY_ON_ERROR = _1 } 30 o.on('-A', '--about', 'show author/license information and exit') { about } 31 o.on('-R', '--readme', 'show README and exit') { readme } 32 o.on('-L', '--list', 'list implemented regions and AIPs') { list } 33 o.on('-V', '--version', 'show version and exit') { version } 34 end.parse! 35 end
Public Instance Methods
run()
click to toggle source
Load necessary files and execute the parser.
@raise [RuntimeError] if the region does not exist
# File lib/aipp/executable.rb 40 def run 41 Pry.rescue do 42 fail(OptionParser::MissingArgument, :region) unless options[:region] 43 AIPP::Parser.new(options: options).tap do |parser| 44 parser.read_config 45 parser.read_region 46 parser.parse_aip 47 parser.validate_aixm 48 parser.write_build 49 parser.write_aixm 50 parser.write_config 51 end 52 rescue => error 53 puts "ERROR: #{error.message}".magenta 54 Pry::rescued(error) if $PRY_ON_ERROR 55 end 56 end
Private Instance Methods
about()
click to toggle source
# File lib/aipp/executable.rb 60 def about 61 puts 'Written by Sven Schwyn (bitcetera.com) and distributed under MIT license.' 62 exit 63 end
list()
click to toggle source
# File lib/aipp/executable.rb 71 def list 72 regions_path = Pathname($0).dirname.join('..', 'gems', "aipp-#{AIPP::VERSION}", 'lib', 'aipp', 'regions') 73 hash = Dir.each_child(regions_path).each.with_object({}) do |region, hash| 74 hash[region] = Dir.children(regions_path.join(region)).sort.map do |aip| 75 File.basename(aip, '.rb') if File.file?(regions_path.join(region, aip)) 76 end.compact 77 end 78 puts hash.to_yaml.sub(/\A\W*/, '') 79 exit 80 end
readme()
click to toggle source
# File lib/aipp/executable.rb 65 def readme 66 readme_path = Pathname($0).dirname.join('..', 'gems', "aipp-#{AIPP::VERSION}", 'README.md') 67 puts IO.read(readme_path) 68 exit 69 end
version()
click to toggle source
# File lib/aipp/executable.rb 82 def version 83 puts AIPP::VERSION 84 exit 85 end