class AIRAC::Executable
Executable
instantiated by the console tools
Attributes
options[R]
Public Class Methods
new()
click to toggle source
# File lib/airac/executable.rb 7 def initialize 8 @options = { 9 format: nil, 10 offset: 0 11 } 12 OptionParser.new do |o| 13 o.banner = <<~END 14 Calculate AIRAC cycle from four digit ID or date within (default: today). 15 Usage: #{File.basename($0)} [options] [cycle] 16 END 17 o.on('-f', '--format TEMPLATE', String, "Template for strftime with %i for cycle ID") { @options[:format] = _1 } 18 o.on('-o', '--offset INTEGER', Integer, "Offset by this many cycles") { @options[:offset] = _1.to_i } 19 o.on('-A', '--about', 'show author/license information and exit') { about } 20 o.on('-V', '--version', 'show version and exit') { version } 21 end.parse! 22 @options[:raw_cycle] = ARGV.shift || Date.today 23 end
Public Instance Methods
run()
click to toggle source
# File lib/airac/executable.rb 25 def run 26 puts (AIRAC::Cycle.new(options[:raw_cycle]) + options[:offset].to_i).to_s(options[:format]) 27 rescue => error 28 message = error.respond_to?(:original_message) ? error.original_message : error.message 29 puts "ERROR: #{message}" 30 end
Private Instance Methods
about()
click to toggle source
# File lib/airac/executable.rb 34 def about 35 puts 'Written by Sven Schwyn (bitcetera.com) and distributed under MIT license.' 36 exit 37 end
version()
click to toggle source
# File lib/airac/executable.rb 39 def version 40 puts AIRAC::VERSION 41 exit 42 end