Class: AIRAC::Executable
- Inherits:
-
Object
- Object
- AIRAC::Executable
- Defined in:
- lib/airac/executable.rb
Overview
Executable instantiated by the console tools
Instance Attribute Summary collapse
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Instance Method Summary collapse
-
#initialize ⇒ Executable
constructor
A new instance of Executable.
- #run ⇒ Object
Constructor Details
#initialize ⇒ Executable
Returns a new instance of Executable.
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/airac/executable.rb', line 7 def initialize = { format: nil, offset: 0 } OptionParser.new do |o| o. = " Calculate AIRAC cycle from four digit ID or date within (default: today).\n Usage: \#{File.basename($0)} [options] [cycle]\n END\n o.on('-f', '--format TEMPLATE', String, \"Template for strftime with %i for cycle ID\") { @options[:format] = _1 }\n o.on('-o', '--offset INTEGER', Integer, \"Offset by this many cycles\") { @options[:offset] = _1.to_i }\n o.on('-A', '--about', 'show author/license information and exit') { about }\n o.on('-V', '--version', 'show version and exit') { version }\n end.parse!\n @options[:raw_cycle] = ARGV.shift || Date.today\nend\n" |
Instance Attribute Details
#options ⇒ Object (readonly)
Returns the value of attribute options.
5 6 7 |
# File 'lib/airac/executable.rb', line 5 def end |
Instance Method Details
#run ⇒ Object
25 26 27 28 29 30 |
# File 'lib/airac/executable.rb', line 25 def run puts (AIRAC::Cycle.new([:raw_cycle]) + [:offset].to_i).to_s([:format]) rescue => error = error.respond_to?(:original_message) ? error. : error. puts "ERROR: #{message}" end |