Class: Inspector::Options

Inherits:
Object
  • Object
show all
Defined in:
lib/inspector/options.rb

Overview

Parses the provided command line flags, switches and arguments

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(argv) ⇒ Options

Initializes Options and parses the provided user input from the command line



17
18
19
# File 'lib/inspector/options.rb', line 17

def initialize(argv)
  parse(argv)
end

Instance Attribute Details

#optionsObject (readonly)

Options hold all the parameters used by the application



13
14
15
# File 'lib/inspector/options.rb', line 13

def options
  @options
end

Instance Method Details

#get_file_from_history(type) ⇒ Object

After running the application output files are saved in the history. –get_file_from_history– retrieves the valid or invalid file from the last application invokation. Where type is eather valid or invalid.

:call-seq:

get_file_from_history(type)


27
28
29
30
31
32
33
34
# File 'lib/inspector/options.rb', line 27

def get_file_from_history(type)
  pattern = Regexp.new('_'+type.to_s)
  File.open(".sycspector.data", 'r') do |file|
    while name = file.gets.chop
      return name unless name.scan(pattern).empty?
    end
  end
end

#save_result_files(opts) ⇒ Object

Save the results of the last run of the application to .sycspector.data. It contains the valid and invalid file as well as the pattern.



38
39
40
41
42
43
44
45
# File 'lib/inspector/options.rb', line 38

def save_result_files(opts)
  File.open(".sycspector.data", 'w') do |file|
    file.puts opts[:valid_file]
    file.puts opts[:invalid_file]
    file.puts opts[:pattern].to_s
    file.puts opts[:scan_pattern].to_s
  end
end