Module: VfrUtils::CLI

Defined in:
lib/vfr_utils/cli.rb

Constant Summary collapse

ALLOWED_ACTIONS =
[
  'metar',
  'taf',
  'notam'
]

Class Method Summary collapse

Class Method Details

.metar(icao_codes) ⇒ Object


36
37
38
39
40
# File 'lib/vfr_utils/cli.rb', line 36

def self.metar(icao_codes)
  require_relative 'metar'
  require_relative 'formatter/weather'
  VfrUtils::Formatter::Weather.pretty_display(VfrUtils::METAR.get(icao_codes))
end

.notam(icao_codes) ⇒ Object


30
31
32
33
34
# File 'lib/vfr_utils/cli.rb', line 30

def self.notam(icao_codes)
  require_relative 'notam'
  require_relative 'formatter/notam'
  VfrUtils::Formatter::NOTAM.pretty_display(VfrUtils::NOTAM.get(icao_codes))
end

.run(argv) ⇒ Object


12
13
14
15
16
17
18
19
# File 'lib/vfr_utils/cli.rb', line 12

def self.run(argv)
  return usage if argv.empty?
  action = argv[0].downcase
  params = argv[1..-1]
  return usage unless ALLOWED_ACTIONS.include? action
  send(action.to_sym, params)
  0
end

.taf(icao_codes) ⇒ Object


42
43
44
45
46
# File 'lib/vfr_utils/cli.rb', line 42

def self.taf(icao_codes)
  require_relative 'taf'
  require_relative 'formatter/weather'
  VfrUtils::Formatter::Weather.pretty_display(VfrUtils::TAF.get(icao_codes))
end

.usageObject


21
22
23
24
25
26
27
28
# File 'lib/vfr_utils/cli.rb', line 21

def self.usage
  STDERR.puts "Version: #{VfrUtils::VERSION} Usage: vfr-utils <action> <params>"
  STDERR.puts ""
  STDERR.puts "Allowed actions:"
  ALLOWED_ACTIONS.each { |action| STDERR.puts "  #{action} <space delimited list of ICAO codes>" }
  STDERR.puts ""
  1
end