Class: XenosEnigma::Runner

Inherits:
Object
  • Object
show all
Defined in:
lib/xenos_enigma/runner.rb

Overview

Runner is responsable for end user interaction via console

Class Method Summary collapse

Class Method Details

.startObject



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/xenos_enigma/runner.rb', line 7

def self.start
  radar_data = nil

  opts = GetoptLong.new(['--help', '-h', GetoptLong::NO_ARGUMENT], ['--path', GetoptLong::OPTIONAL_ARGUMENT])
  opts = Hash[*opts.get_option]

  if opts['--help']
    puts 'Usage: bin/run [--path FILE]'
    puts "--help  \t show help"
    puts "--path FILE \t set path to radar data file, uses default data if no file provided"
    exit(0)
  end

  if (file_provided = opts['--path'])
    unless File.exist?(file_provided)
      warn "File #{file_provided} not found"
      exit(1)
    end

    radar_data = File.read(file_provided)
  end

  radar = XenosEnigma::Radar.new(radar_data)
  radar.scan
  radar.echo
end