Class: Matrixeval::CommandLine

Inherits:
Object
  • Object
show all
Defined in:
lib/matrixeval/command_line.rb,
lib/matrixeval/command_line/parse_init_arguments.rb,
lib/matrixeval/command_line/parse_context_arguments.rb

Defined Under Namespace

Classes: ParseContextArguments, ParseInitArguments

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(argv) ⇒ CommandLine

Returns a new instance of CommandLine.



12
13
14
# File 'lib/matrixeval/command_line.rb', line 12

def initialize(argv)
  @argv = argv
end

Instance Attribute Details

#argvObject (readonly)

Returns the value of attribute argv.



10
11
12
# File 'lib/matrixeval/command_line.rb', line 10

def argv
  @argv
end

Instance Method Details

#all?Boolean

Returns:

  • (Boolean)


30
31
32
# File 'lib/matrixeval/command_line.rb', line 30

def all?
  context_options[:all]
end

#context_argumentsObject



38
39
40
41
42
# File 'lib/matrixeval/command_line.rb', line 38

def context_arguments
  arguments = @argv[0...seperator_index]
  arguments << "-h" if @argv.empty?
  arguments
end

#context_optionsObject



34
35
36
# File 'lib/matrixeval/command_line.rb', line 34

def context_options
  @context_options ||= ParseContextArguments.call(context_arguments)
end

#init?Boolean

Returns:

  • (Boolean)


22
23
24
# File 'lib/matrixeval/command_line.rb', line 22

def init?
  @argv[0] == 'init'
end

#init_optionsObject



26
27
28
# File 'lib/matrixeval/command_line.rb', line 26

def init_options
  @init_options ||= ParseInitArguments.call(@argv[1..-1])
end

#rest_argumentsObject



44
45
46
# File 'lib/matrixeval/command_line.rb', line 44

def rest_arguments
  @argv[seperator_index..-1]
end

#valid?Boolean

Returns:

  • (Boolean)


16
17
18
19
20
# File 'lib/matrixeval/command_line.rb', line 16

def valid?
  init? ||
    !context_options.empty? ||
    !seperator_index.nil?
end